Pickle Posted January 21, 2012 Share Posted January 21, 2012 Hi Everyone I have a weird session issue going on and i'm not sure what is causing it. Basically any sessions that i set are randomly expiring sooner than they should be. As a test I did the following: <?php session_start(); if(isset($_SESSION['views'])){ $_SESSION['views'] = $_SESSION['views']+ 1; }else{ $_SESSION['views'] = 1; } echo "views = ". $_SESSION['views']; echo '<p><a href="testpage.php">Refresh</a></p>'; ?> If i continue to click the refresh button, i sometimes get to 30 and then it starts at 1 again. Other times ill get to 20 and then back to 1. It has also sometimes skips a couple of counts from 7 to 11 as an example in one click. Any one come across this before? I have been reading up online and some have mentioned PHP upgrades from php4 to php5 cause some issues and specifically the hosting company changing the session.save_path. If this was the case, it wouldn't even count to 10, would it? Any help would be really appreciated. thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/255476-wierd-session-issue/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 21, 2012 Share Posted January 21, 2012 Are you doing this on your local development system or on shared web hosting? Quote Link to comment https://forums.phpfreaks.com/topic/255476-wierd-session-issue/#findComment-1309831 Share on other sites More sharing options...
Pickle Posted January 21, 2012 Author Share Posted January 21, 2012 its on shared web hosting. thanks Quote Link to comment https://forums.phpfreaks.com/topic/255476-wierd-session-issue/#findComment-1309832 Share on other sites More sharing options...
PFMaBiSmAd Posted January 22, 2012 Share Posted January 22, 2012 If your session.save_path is set to the default \tmp folder, it means that the session settings of all the accounts running on the server will affect your session data files too. The symptom you have described usually occurs when someone sets the session.gc_maxlifetime to a short value in a misguided attempt to get the session handling to log out inactive users. On shared web hosting, you need to make your own folder for the session data files and set the session.save_path setting to point to your own folder. The session.save_path must be set before every session_start statement, so that your session data files will only be stored and referenced in your own folder. If you have the ability to create folders that are outside of your document_root folder (closer to the root of the disk), that is the best place to create this folder. If you only have the ability to create folders inside your document_root folder, you will also need to put a .htaccess file in the folder to prevent all HTTP requests to the files in that folder. Quote Link to comment https://forums.phpfreaks.com/topic/255476-wierd-session-issue/#findComment-1309951 Share on other sites More sharing options...
Pickle Posted January 22, 2012 Author Share Posted January 22, 2012 Hi thanks for your reply, I really appreciate the help You are right, the session.save_path is set to \tmp. They do give me the option to change the path to something else via their control panel. I will create a new folder and change the path and hopefully it will go back to normal. I have access to one level up from the document_root, so i will give that a go. Should i put a .htaccess file in there anyway? By creating my own folder, does this solve the issue of the session.gc_maxlifetime being a short value or would I need to ask them to increase this for me? I also read somewhere that it might be to do with virtual memory, is that correct? thanks again Quote Link to comment https://forums.phpfreaks.com/topic/255476-wierd-session-issue/#findComment-1309995 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.