Jump to content

Sessions...this May Help Others Dealing With The Issue


Recommended Posts

After struggling all day with trying to get my session variables to carry over to the next page I nearly gave up.

 

I knew I had my variable set because I could echo it out on the page it was on. But as soon as I went to the next page it wouldn't work.

 

So I tried one last thing... Instead of doing a header redirect to the next page I used the old fashioned:

 

print "<script>";
print " self.location='newpage.php';";
print "</script>";

 

and as soon as I made that changed I was able to echo both my session variable and the local variable I created from the session variable.

 

For some reason This:

 

header("location: newpage.php"); 

 

Will destroy your session.

 

There may be a work around I'm not aware of someone can share with me but after being half bald now from frustration hair pulling I figured I would pass along the information because I didn't find this on the 5,348,283,489 websites I visited today reading about sessions.

There's nothing inherent in a header('location: ....') redirect statement that would cause sessions to not work. It's more likely that your actual redirect was changing the host-name (www. vs no-www) or the path after the domain (and your session cookie parameters are net setup to match variations in the host-name or path) or you have some code on the page after the header() statement that is clearing the session variable(s) while the browser is requesting the new page (the header() statement doesn't stop php from running, it only sends a header to the browser.)

Edited by PFMaBiSmAd

There's nothing inherent in a header('location: ....') redirect statement that would cause sessions to not work. It's more likely that your actual redirect was changing the host-name (www. vs no-www) or the path after the domain (and your session cookie parameters are net setup to match variations in the host-name or path) or you have some code on the page after the header() statement that is clearing the session variable(s) while the browser is requesting the new page (the header() statement doesn't stop php from running, it only sends a header to the browser.)

 

Actually I didn't. I had them just as shown in my code above. Didn't use full paths in either case. Changed nothing else either. Just that and it started working. Which is strange because all my admin area scripts I use sessions on I've never had a problem. Not sure why this made a diff on this project. But it did.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.