divinecoder Posted February 23, 2007 Share Posted February 23, 2007 Hi, Session gets expired immidately in the next page. It works fine in the same page as it gets set in the page each time the page is refreshed. Kindly help me. Thanks Quote Link to comment Share on other sites More sharing options...
ldsmike88 Posted February 23, 2007 Share Posted February 23, 2007 Do you mean everything works fine on the first page but if you try to move session variables to another page the session isn't registered? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 23, 2007 Share Posted February 23, 2007 Please post some code between tags Ken Quote Link to comment Share on other sites More sharing options...
ldsmike88 Posted February 23, 2007 Share Posted February 23, 2007 Please explain your problem a little more so I can help you out. Thanks Michael Quote Link to comment Share on other sites More sharing options...
divinecoder Posted February 23, 2007 Author Share Posted February 23, 2007 Hi Friends, Thanks for your initiatives to help me. Here is my code: <? ob_start(); session_start(); if ($_GET['x']!="" && $_SESSION['custKey']=="") { $ky=$_GET['x']; $_SESSION['custKey']=$ky; } if ($_GET['page'] == "login"){ include("login.php"); } elseif ( $_GET['page'] == "cust_main" ) { include("custmain.php"); } /*custmain.php*/ if (isset($_SESSION['custKey'])) $cust_key=$_SESSION['custKey']; else header("location:index.php?page=login&redirect=cust_main"); The above code works if i have the url as: www.mydon.com/index.php?page=cust_main&x=5 immidiately after the above url is run if i remove x=5 and use only www.mydon.com/index.php?page=cust_main it redirects me to login page. Please let me know if am not clear in explaining you. Thanks Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 23, 2007 Share Posted February 23, 2007 because each time you're resetting it. $ky=$_GET['x']; $_SESSION['custKey']=$ky; So the first time it's set, so the session variable gets set. The second time, it's null, so the session variable is ALSO null. Quote Link to comment Share on other sites More sharing options...
divinecoder Posted February 23, 2007 Author Share Posted February 23, 2007 sorry i missed to paste it here i already have a checking there for it. I have modifed the code. Kindly check it. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 23, 2007 Share Posted February 23, 2007 Try this: if (isset($_GET['x']) && !isset($_SESSION['custKey'])) { $ky=$_GET['x']; $_SESSION['custKey']=$ky; } Quote Link to comment Share on other sites More sharing options...
divinecoder Posted February 23, 2007 Author Share Posted February 23, 2007 Hi, Thanks for your reply. Actually i feel this is not a problem with my code, i feel some config problem but unable to figure out what it is. This code works fine locally. But not in the server. Any how i tried what you said too , still it does not works. Thanks Quote Link to comment Share on other sites More sharing options...
divinecoder Posted February 23, 2007 Author Share Posted February 23, 2007 I checked php info, it seems to be fine. THats why confused. session Session Support enabled Registered save handlers files user sqlite Registered serializer handlers php php_binary wddx Directive Local Value Master Value session.auto_start Off Off session.bug_compat_42 Off Off session.bug_compat_warn On On session.cache_expire 180 180 session.cache_limiter nocache nocache session.cookie_domain no value no value session.cookie_lifetime 0 0 session.cookie_path / / session.cookie_secure Off Off session.entropy_file no value no value session.entropy_length 0 0 session.gc_divisor 100 100 session.gc_maxlifetime 1440 1440 session.gc_probability 1 1 session.hash_bits_per_character 4 4 session.hash_function 0 0 session.name PHPSESSID PHPSESSID session.referer_check no value no value session.save_handler files files session.save_path /var/php_sessions /var/php_sessions session.serialize_handler php php session.use_cookies On On session.use_only_cookies Off Off session.use_trans_sid 1 1 Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 23, 2007 Share Posted February 23, 2007 add print_r($_SESSION); at the top of the page, after session_start(), so we can see if the variables are really there. Quote Link to comment Share on other sites More sharing options...
divinecoder Posted February 23, 2007 Author Share Posted February 23, 2007 i tried that too i only had "array()" Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 23, 2007 Share Posted February 23, 2007 Well you need to view the page more than once, like take off your x=5 part. The first time the session will be empty, so there are no values. So if you add it at the bottom too, you should see the change, the session variables got assigned. Quote Link to comment Share on other sites More sharing options...
divinecoder Posted February 23, 2007 Author Share Posted February 23, 2007 yes, it shows when adding immidiately below where session is set but not shows when x=5 is removed from url(second time i.e first time url with x=5) Quote Link to comment Share on other sites More sharing options...
Archadian Posted February 23, 2007 Share Posted February 23, 2007 in your php.ini file make sure session.use_only_cookies is set to 0...the name "use_only_cookies" kinda gives it away Quote Link to comment Share on other sites More sharing options...
divinecoder Posted February 23, 2007 Author Share Posted February 23, 2007 In php info it shows as session.use_only_cookies Off Off is that fine. I have posted the phpinfo in one of the above posts Thanks Quote Link to comment Share on other sites More sharing options...
Archadian Posted February 23, 2007 Share Posted February 23, 2007 try setting to this session.use_only_cookies=0 if that doesn't work try making session_start(); the first thing after <?php I know you said its set to off but try session.use_only_cookies=0 because i was getting Array() also and i changed that to 0 and everything works now Quote Link to comment Share on other sites More sharing options...
divinecoder Posted February 23, 2007 Author Share Posted February 23, 2007 No it dint work. Thanks a lot for your initiatives this is in the top of the page <?session_start(); ini_set('session.use_only_cookies','0'); ?> i tried this too <? ini_set('session.use_only_cookies','0'); session_start(); ?> Quote Link to comment Share on other sites More sharing options...
Archadian Posted February 23, 2007 Share Posted February 23, 2007 oh i meant where your session.use_only_cookies is in your php.ini change to session.use_only_cookies=0 i tried what you did above and it didn't work for me either also make sure (in your php.ini file) the session.save_path is writable and readable for your server Quote Link to comment 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.