Loosing my session
Posted: Wed Jun 16, 2004 2:26 pm
This code might help. This first part is my login page that registers the session. The second code is the code i put at the top of each member page so if the session is not set it makes you log back in. It does take me to mypage right away and let me view it however if i hit refresh it sends me back to loginbox.php.
I can echo the sessionid and get the same session id, but it seems i am loosing $_SESSION['name'] which i think is why it is doing this. Any ideas to why i am loosing it?
Thank you
Anthony
Thank you for your time and help
I can echo the sessionid and get the same session id, but it seems i am loosing $_SESSION['name'] which i think is why it is doing this. Any ideas to why i am loosing it?
Thank you
Anthony
Code: Select all
<?php$lastlogon = date("l, M, d");
$pass = md5($pass);
$sql = "SELECT * FROM users where user='$uname' and pass='$pass'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
if ($row["user"] == $uname && $row["pass"] == $pass) {
$lastlogon = date("l, M, d");
session_start();
$_SESSION['name'] = $uname;
if(isset($_SESSION['name'])) {
$sqll = "UPDATE users SET last_logon='$lastlogon' WHERE user='".$_POST['uname']."'";
if(mysql_query($sqll)) {
header("location: mypage");
}
else {
echo "Couldn't update user<br />".$sqll."<br />".mysql_error()."";
}
}
else {
echo "Couldn't Set User Session";
}
}
else {
$output = "<center><font face=arial size=-1 color=red>Username/Password do not match <a
href=loginbox.php>Click here to login again</a></font></center>";
include('html.inc');
start_header($output);
}
?>Code: Select all
<?php
session_start();
header("Cache-control: private");
$name = $_SESSION['name'];
if($_SESSION['name'] == "") { header("Location: http://www..com/test.php"); exit; }
?>