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[”]))
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’]))
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.
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();
}
}
}
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();