<?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);
}
?>
That is my login code which logs the user in. and now the following code is the code that says if the user is not logged in then send them to the login page. What is happening is on mypage i have it echo $_SESSION['name']; and it does that just fine. However, when i hit refresh on the page, the name is unset. I still have an open session but name isn't set. Any ideas?
<?php
session_start();
header("Cache-control: private");
$name = $_SESSION['name'];
if($_SESSION['name'] == "") { header("Location: [url]http://www..com/test.php[/url]"); exit; }
?>
Thank you
Anthony