tiptip Posted January 17, 2013 Share Posted January 17, 2013 hello , im having some problem, and i did google alot and try different solution non have worked, ill try to give as much details as i can.. my code conatain some stuff like getting info from mysql DB , but i paste here only the part of code i have problem with. also i wrote this simple session code in my page just to make easy check on if it works. code: <?php session_start(); $_SESSION['test'] = "adam"; header('location: http://******.Index.php'); ?> now this code sit in a file called check.php and it called from an other php file contain form. now when the code run like this , and i move to page index.php the "echo $_SESSION['test'];" return empty. when i remove the header and put <a> tag link to index.php again "echo $_SESSION['test'];" return empty. when i remove the header totally, the call this code, and then write the link "www.****/.index.php" in the browser url bar , then echo $_SESSION['test']; return "adam" like it should... after looking on this problem on google, i try to add exit(0); after the header , that didnt work. also try to add session_write_close(); before the header , this also didnt work... any ideas??? thanks a head Quote Link to comment https://forums.phpfreaks.com/topic/273276-session-problems/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 17, 2013 Share Posted January 17, 2013 Your links and redirect statements are changing the www. vs no-www. in the URL and the session id cookie doesn't match all variations of your domain name. A) You need to be consistent in using a www. or no-www. on your domain name, B) You need to redirect any request that doesn't have the www. on it to the same url with the www. on it (or visa-versa.) C) You need to set the session cookie id domain setting so that it matches all variations of your domain name. See the 'domain' parameter at this link - http://us1.php.net/session_set_cookie_params Quote Link to comment https://forums.phpfreaks.com/topic/273276-session-problems/#findComment-1406447 Share on other sites More sharing options...
tiptip Posted January 17, 2013 Author Share Posted January 17, 2013 well thanks alot. after you showed me what is the problem, i was able to solve it in much easyer way , i just redirect path to the file in my server, and not call www .... but i still was reading about session_set_cookie_params and i gonna play with it little just for the understanding... thanks for your help... Quote Link to comment https://forums.phpfreaks.com/topic/273276-session-problems/#findComment-1406453 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.