Tidus
02-08-2006, 12:02 PM
Hey guys,
Got a problem here thats really getting under my skin, i've had it for days!
I'm basically working on a user authentication based site, so users need to login before being able to access it - the user data is stored in a mysql db..
Here's the problem..
User can login fine first time with username and password.. The sessions are working fine, however when the user logs out and tries to login with a different username and password, 3 of the session variables stay the same as the old user?!
For example;
The 4 vars i store in sessions are
uid, username, password, emailaddress.
So when the user logs out and then logs back in with a different username and password, the site all works but is using the old users details, the only thing that changes in the session is the email address... if you get me.
Here's my login and logout scripts.
session_start();
header("Cache-control: private");
//CHECK IF THERE IS A COOKIE
if (!isset($_COOKIE['info'])) {
// NO COOKIE SO LETS LOGIN USING THE VARS PASSED FROM LOGIN
$username1 = $_POST['username'];
$password1 = $_POST['password'];
// DB CONNECT HERE
$query = "SELECT * FROM users WHERE username='$username1' AND password='$password1'";
$result = mysql_query($query);
$myrow = mysql_fetch_array($result);
$uidc = $myrow["uid"];
$usernamec = $myrow["username"];
$passwordc = $myrow["password"];
$emailaddressc = $myrow["emailaddress"];
//NOW WE CAN CHECK IF THE USER IS IN THE DB
if (mysql_numrows($result) == 1) {
$_SESSION['username'] = $usernamec;
$_SESSION['uid'] = $uidc;
$_SESSION['password'] = $passwordc;
$_SESSION['emailaddress'] = $emailaddressc;
echo "<script language='JavaScript1.2' type='text/javascript'>
top.parent.location = 'http://www.SITEHERE.com/main/?';
</script>";
}else{
echo "WRONG INFO";
}
}
The reason it looks so messy is because i've been trying to get it working..
Here is the logout script..
session_start();
unset($_SESSION[session_name()]);
$_SESSION = array();
if (isset($_COOKIE[session_name()]))
{
setcookie(session_name(), '', time() - 42000, '/');
}
session_destroy();
header("Location: http://www.xxxx.com/openindex.php");
If anyone can help please that would be great.. if you dont understand what i mean and want to see it in action just email me jholz@iinet.net.au and i'll show u what its doing.
Thanks heaps!!
Got a problem here thats really getting under my skin, i've had it for days!
I'm basically working on a user authentication based site, so users need to login before being able to access it - the user data is stored in a mysql db..
Here's the problem..
User can login fine first time with username and password.. The sessions are working fine, however when the user logs out and tries to login with a different username and password, 3 of the session variables stay the same as the old user?!
For example;
The 4 vars i store in sessions are
uid, username, password, emailaddress.
So when the user logs out and then logs back in with a different username and password, the site all works but is using the old users details, the only thing that changes in the session is the email address... if you get me.
Here's my login and logout scripts.
session_start();
header("Cache-control: private");
//CHECK IF THERE IS A COOKIE
if (!isset($_COOKIE['info'])) {
// NO COOKIE SO LETS LOGIN USING THE VARS PASSED FROM LOGIN
$username1 = $_POST['username'];
$password1 = $_POST['password'];
// DB CONNECT HERE
$query = "SELECT * FROM users WHERE username='$username1' AND password='$password1'";
$result = mysql_query($query);
$myrow = mysql_fetch_array($result);
$uidc = $myrow["uid"];
$usernamec = $myrow["username"];
$passwordc = $myrow["password"];
$emailaddressc = $myrow["emailaddress"];
//NOW WE CAN CHECK IF THE USER IS IN THE DB
if (mysql_numrows($result) == 1) {
$_SESSION['username'] = $usernamec;
$_SESSION['uid'] = $uidc;
$_SESSION['password'] = $passwordc;
$_SESSION['emailaddress'] = $emailaddressc;
echo "<script language='JavaScript1.2' type='text/javascript'>
top.parent.location = 'http://www.SITEHERE.com/main/?';
</script>";
}else{
echo "WRONG INFO";
}
}
The reason it looks so messy is because i've been trying to get it working..
Here is the logout script..
session_start();
unset($_SESSION[session_name()]);
$_SESSION = array();
if (isset($_COOKIE[session_name()]))
{
setcookie(session_name(), '', time() - 42000, '/');
}
session_destroy();
header("Location: http://www.xxxx.com/openindex.php");
If anyone can help please that would be great.. if you dont understand what i mean and want to see it in action just email me jholz@iinet.net.au and i'll show u what its doing.
Thanks heaps!!