Jump to content

PHP Session Timing out


jack5100nv

Recommended Posts

I have a script that is storing some info in session variables. However, the sessions timeout rather quickly and abruptly even when I am using the app. I thought as long as you are using the app, the session won't timeout. Is there anyway I can force it to keep the session open as long as the user is using the app?

Link to comment
https://forums.phpfreaks.com/topic/100372-php-session-timing-out/
Share on other sites

Yes, i have session_start(); on top of a page. It is actually one page and I am including other php files in that one page. The main page has all the design and other php pages are being called into that one page for example index.php?page=aboutus  and  index.php?page=contactus  Depening on $page, I include the correct page in index.php and display it. session_start();  is on top of index.php

What about the session id though, is it being reset?  If you echo out session_id() while your browsing through the site it should remain the same.  When the other var goes blank, does the session id actually change?  If it doesn't then the session isn't being lost, it's being unset somewhere, that's why I want to do this test.

If you are on a shared host, some other account has probably set a short session.gc_maxlifetime, thinking they were using that to log someone out.

 

So, if you are on a shared host, you need to set the session.save_path to point to a private folder within your account so that session.gc_maxlifetime that other scripts are using don't delete your session data files.

PFMaBiSmAd , I am using a shared host. It makes sense. How do i set the session.save_path to point to a private folder within my account so that session.gc_maxlifetime that other scripts are using don't delete my session data files?

 

p2grace , I am also going to run the test of session_id to see if it being reset.

The session does not loose the value at the same place and not in the same time interval. Its totally random. I haven't tried out the session path yet. Actually I am going to distribute this script on the internet when I am done developing it, so I want to have very few things for my users to configure. Looks like every user will have to configure the path when they install it and I want them to go through as little steps as possible.

 

Could it be that someone else on the shared server is using a session variable with the same name. Could that cause problem? But in this case I should see the value of their session variable when i am echoing it but i just get an empty variable.

Could it be that someone else on the shared server is using a session variable with the same name.

 

No, sessions don't work that way and if you are asking that, you probably need to read this - http://php.net/session

 

There are two possibilities, your code contains a logic problem that is causing the session to be cleared (we haven't seen your code so that possibility cannot be ruled out) or the session data file is being deleted due to garbage collection running with a short interval on a busy shared host or on non-busy shared host where someone has messed with the session.gc_probability and session.gc_divisor settings in addition to messing with the session.gc_maxlifetime.

 

If the problem is that garbage collection is running frequently with a short lifetime due to some other account on a server, then the only solutions are to change the session.save_path to be a private folder or to use a custom session save handler so that where and how the session data files work is under your control.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.