if (isset($_POST['login'])) {
$query = mysql_query("
SELECT id FROM users
WHERE username = '".mysql_real_escape_string($_POST['username'])."'
AND password = '".mysql_real_escape_string($_POST['password'])."'
");
/* wrong login information? output a message and terminate the script */
if (!mysql_num_rows($query)){
header("Location: error.php");
exit();
}
/* set session with unique index */
$_SESSION['id'] = mysql_result($query, 0, 'id');
mysql_query("UPDATE users SET last_login = NOW(), last_ip = '".$_SERVER['REMOTE_ADDR']."' WHERE id = '{$_SESSION['id']}'");
header("Location: success.php");
exit;
}
/* destroy session */
if (isset($_GET['logout'])){
mysql_query("UPDATE users SET online = '0' WHERE id = '{$_SESSION['id']}'");
session_unset();
session_destroy();
header("Location: index.php");
exit;
}
It works, it does send me to success php on right info but this is what im trying to do:
if (!$_SESSION['id']) {
} else { echo "Logged in"; }
It dont show "Logged in", i have try printed $_SESSION['id'] but nothing. Its all in index.php. What can be the problem? and dont worry about no hash..gonna fix that later
No comments:
Post a Comment