I have some login script code that i got from some tutorial and it works perfectly on another site of mine but i need to modify it to work with a new website: budgetme.org
I can open the login form and submit it but the way the checkuser script is written it redirects to a login success and a login fail page respectivly. I want it to simple give a "wrong username" above the login form or redirct to the home page with the user logged in.
Can someone please tell me how i can do this??? the jquerry im using for the login box is located on the website home page. Thanks so much!!
Here is the check user script im using (modified to work with my system).
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Check User</title>
</head>
<body>
<?
/* Check User Script */
// Start Session
include 'db.php';
// Conver to simple variables
$username = $_POST['username'];
$password = $_POST['password'];
if((!$username) || (!$password)){
echo "Please enter your username and password. <br />";
exit();
}
// Convert password to md5 hash
$password = md5($password);
// check if the user info validates the db
$sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' ");
$login_check = mysql_num_rows($sql);
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
foreach( $row AS $key => $val ){
$$key = stripslashes( $val );
}
// Register some session variables!
session_register('id');
$_SESSION['id'] = $id;
session_register('username');
$_SESSION['username'] = $username;
session_register('password');
$_SESSION['password'] = $password;
session_register('sign_up');
$_SESSION['sign_up'] = $sign_up;
session_register('email');
$_SESSION['email'] = $email;
session_register('first');
$_SESSION['first'] = $first;
session_register('last');
$_SESSION['last'] = $last;
session_register('activation');
$_SESSION['activation'] = $activation;
session_register('user_level');
$_SESSION['user_level'] = $user_level;
session_register('total_amount');
$_SESSION['total_amount'] = $total_amount;
session_register('budget_1_name');
$_SESSION['budget_1_name'] = $budget_1_name;
session_register('budget_1_total');
$_SESSION['budget_1_total'] = $budget_1_total;
session_register('budget_2_name');
$_SESSION['budget_2_name'] = $budget_2_name;
session_register('budget_2_total');
$_SESSION['budget_2_total'] = $budget_2_total;
session_register('budget_3_name');
$_SESSION['budget_3_name'] = $budget_3_name;
session_register('budget_3_total');
$_SESSION['budget_3_total'] = $budget_3_total;
session_register('budget_4_name');
$_SESSION['budget_4_name'] = $budget_4_name;
session_register('budget_4_total');
$_SESSION['budget_4_total'] = $budget_4_total;
session_register('budget_5_name');
$_SESSION['budget_5_name'] = $budget_5_name;
session_register('budget_5_total');
$_SESSION['budget_5_total'] = $budget_5_total;
mysql_query("UPDATE users SET last_login=now() WHERE userid='$userid'");
header( "Location: index.php" );
}
} else {
echo "The login information you entered does not match our system.";
}
?>
</body>
</html>
<? ob_flush(); ?>