Jump to content

wierd session issue


Pickle

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.