Page 1 of 1

Sessions dropping

Posted: Wed Mar 24, 2004 8:18 am
by lostboy
i am having some problems keeping my session vars alive. i have a user log-in form which sets a session before redirecting the user to another page. In this page I check for the existence of that session var and it seems to be loosing the session as it directs users back to the log in...

Note: most of the code is in functions

Code: Select all

//code to check the log in and set the session var

$result = mysql_query($sql_id,$conn) or die("Can't retrieve user because ".mysql_error());
    if ($result){
      while($row = mysql_fetch_array($result)){
        $user_id = $row['user_id'];
      }
    }//end if

      $_SESSION['user_id'] = $user_id;

    header("location:my_ads.php?a=show");
Any ideas as to why this may drop sessions info?

Posted: Wed Mar 24, 2004 12:24 pm
by malcolmboston
im assuming you are calling

Code: Select all

session_start();
at the beginning of th next page right?

Posted: Wed Mar 24, 2004 12:30 pm
by lostboy
of course...didn't see the need to burden everyone with the entire page...

Posted: Wed Mar 24, 2004 12:34 pm
by malcolmboston
try this piece of pseudo-code

Code: Select all

$result = mysql_query($sql_id,$conn) or die(mysql_error()); 
if ($result)
{ 
      while($row = mysql_fetch_array($result)){ 
        $user_id = $row['user_id']; 
}
$_SESSION['user_id'] = "$user_id";
if (isset($_SESSION['user_id'])
{
// continue
// do something
}
else
{
// the session doesnt exist
header("location:my_ads.php?a=show");
exit();
}