/    Sign up×
Community /Pin to ProfileBookmark

$_POST Stealing if (isset)’s !!!!!!

i’m trying to sort out a user authentication system that i’ve pieced together from a few books etc. and i’m having problems with

[code=php]if (isset($_POST[”]))[/code]

The problem i’m having is that the wrong ones keep excuting!!! I have a submit button named = login_button, and when ever it’s pressed, the code following

[code=php]if (isset($_POST[‘date_find’]))[/code]

is executed!!

The log in buttons are constantly on screen over all pages and the code for them is in the header & footer, and obviously the if (isset($_POST[”]))’s that run are the different pages that sit in between them.

CODE
———————-

Header code:

[code=php]ob_start();
session_start();

if (isset($_POST[‘login_button’]))
{
require_once (‘database.php’);
if (!empty($_POST[‘username’]) && !empty($_POST[‘password’]))
{
$u = escape_data($username);
$p = escape_data($password);

$phashed = md5($p);

$query_user = “SELECT user_id, first_name, admin
FROM user
WHERE username = $u AND password = PASSWORD(‘$phashed’)”;
$result_user = mysql_query($query_user);
$row_user = mysql_fetch_array($result_user, MYSQL_NUM);

if ($row_user)//If a match is made
{
//Start the session
$_SESSION[‘user_id’] = $row_user[0];
$_SESSION[‘first_name’] = $row_user[1];
$_SESSION[‘admin’] = $row_user[2];

ob_end_clean();

header(“Location: http://” . $_SERVER[‘HTTP_HOST’] . dirname($_SERVER[‘PHP_SELF’]) . “/index.php”);

exit();
}
}
}[/code]

Footer code:

[code=php]
echo ‘<div class=”login”><form action=”‘.$php_self.'” method=”post”>’;
if (isset($_SESSION[‘user_id’]))
{
echo ‘<div<p><b>’.$first_name.’ Logged in!</b></p>’;
echo ‘<input type=”submit” name=”logout” value=”Log Out”></form></div>’;
}
else
{
echo ‘<b>User Name:</b><br /><input type=”text” name=”username” id=”username” size=”15″ maxlength=”20″ /><br />’;
echo ‘<b>Password:</b><br /><input type=”password” name=”password” id=”password” size=”15″ maxlength=”20″ /><br />’;
echo ‘<input type=”submit” name=”login_button” value=”Login” /></form></div>’;
}
ob_end_flush();[/code]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@bokehAug 11.2005 — I don't fully understand what you are saying.

try inserting the following at the top of your script for testing:
[code=php]foreach($_POST as $key => $value){
echo "$key => $value <br> n";
}[/code]
Now you will be able to see exactly what is and is not set.
×

Success!

Help @Durbs spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...