Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

session dropping issues

Status
Not open for further replies.

bastienk

Programmer
Joined
Mar 3, 2004
Messages
326
Location
CA
Hi All

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:
//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?

Cat, the other other white meat
 
have you initialized, or resumed, the session? By calling session_start()?

That would be the first step if you haven't already. You must call this function prior to setting any session variables.
 
yes, one each page of the app

Cat, the other other white meat
 
is that the complete code to check the login? how can you be sure that the var $user_id has something?

put an "echo $user_id;" after "$_SESSION['user_id'] = $user_id;"... obviously you will get an "header already sent" error, but it is only to make sure that the user id does exist.
 
Chacalinc
The user ID exists, the sql takes care of that...

sleipnir214
Unix - not sure what flavor - the client doesn't want to give me access to the server to run any checks (like phpinfo(); )

Cat, the other other white meat
 
Edit The code snippet shown is from the registration area, I am using the same variables that I created the record with to extract the id. Perhaps not the most efficient, I know, but it will return a record....



Cat, the other other white meat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top