Loosing my session

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

Loosing my session

Post by pinehead18 »

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

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; }
?>
Thank you for your time and help
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

did you really have to create a new thread for this? :roll:
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

Post by pinehead18 »

Sorry forgot to edit it.
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

Post by pinehead18 »

on mypage. I echo $_SESSION['name']; and it works, but when i refresh it goes away. Why is this becomming unset? Do i need to do something to keep it set?
Post Reply