dpiearcy Posted December 16, 2012 Share Posted December 16, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/272046-sessionsthis-may-help-others-dealing-with-the-issue/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 16, 2012 Share Posted December 16, 2012 (edited) 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 December 16, 2012 by PFMaBiSmAd Quote Link to comment https://forums.phpfreaks.com/topic/272046-sessionsthis-may-help-others-dealing-with-the-issue/#findComment-1399626 Share on other sites More sharing options...
dpiearcy Posted December 16, 2012 Author Share Posted December 16, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/272046-sessionsthis-may-help-others-dealing-with-the-issue/#findComment-1399627 Share on other sites More sharing options...
trq Posted December 16, 2012 Share Posted December 16, 2012 Instead of advertising this as a solution to a problem that doesn't usually exist, why don't you post your problematic code? Quote Link to comment https://forums.phpfreaks.com/topic/272046-sessionsthis-may-help-others-dealing-with-the-issue/#findComment-1399632 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.