I'm using php Sessions on my website and it seems like they are "disappearing" at random intervals. I don't know if they are timing out due to inactivity or if something is wrong with my code, but is there some way to control the sessions of when they expire?
Like can I put something in my code or change something in the php.ini file?
Update- So just and update here, I switched hosts and magically the sessions started working. I have no clue what was wrong but apparently they did not want to work correctly.
By default, session variables last until the user closes the browser. So; Session variables hold information about one single user, and are available to all pages in one application. Tip: If you need a permanent storage, you may want to store the data in a database.
The timeout limit of the session can be set by setting the value of two directives in the php. ini file or using the ini_set() function in the PHP script. The directives are given below. It is used to set the time limit in seconds to store the session information in the server for a long time.
Click Servers > Server Type > WebSphere Application Servers > CongnosX_GW2. Click Container Settings > Session management > Set Timeout. Enter the desired timeout value in minutes. Click OK.
1440 seconds is the default which is actually 24 minutes.
Random expiration is a classical symptom of session data directory shared by several applications: the one with the shortest session.gc_maxlifetime
time is likely to remove data from other applications. The reason:
The builtin file handler doesn't track who owns what session file (it just matches file name with session ID):
My advice is that you configure a private custom session directory for your application. That can be done with the session_save_path()
function or setting the session.save_path
configuration directive. Please check your framework's documentation for the precise details on how to do it in your own codebase.
Debian uses a cron job to automatically expire sessions in a secure manner. If you are using Debian, look at /etc/cron.d/php5.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With