Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

retrieve php server session timeout

Tags:

php

session

I want to retrieve the value of session.gc_maxlifetime from the PHP server settings ( the time after which the session expires after no activity ). Very important : I do not want to change it, I only wish to retrieve its value ( maybe the value is different from server to server ) and I want to use a PHP script that I made to warn users properly, depending on the settings of those server.

Thank you.

like image 848
NVG Avatar asked Feb 10 '13 09:02

NVG


People also ask

How check session expired in php?

You need to use session_encode() and session_decode(). The former will only read data from the $_SESSION array so eavesdropping on sessions requires some careful subversion of session_id() and session_start() . session_decode() however will happily convert anything you throw at it.

How long does a session in php last?

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.

What is php default session timeout?

1440 seconds is the default which is actually 24 minutes.

How can I see the session timeout of a website?

If you want to determine when the countdown for timeout starts, you can can go to the Logic tab, right-click on the Server Actions folder, select Add System Event and then On Begin Web Request. This will create an action that will run every time your module handles a new request.


2 Answers

That's where ini_get function comes in hand:

$maxlifetime = ini_get("session.gc_maxlifetime");

From manual we read:

session.gc_maxlifetime integer session.gc_maxlifetime specifies the number of seconds after which data will be seen as 'garbage' and potentially cleaned up. Garbage collection may occur during session start (depending on session.gc_probability and session.gc_divisor).

like image 151
n-dru Avatar answered Oct 13 '22 11:10

n-dru


session.gc_maxlifetime is not the time after which the session expires after no activity. gc here may be mean garbage collenction. As the php manual says,

session.gc_maxlifetime specifies the number of seconds after which data will be seen as 'garbage' and potentially cleaned up. Garbage collection may occur during session start (depending on session.gc_probability and session.gc_divisor).

Note: If different scripts have different values of session.gc_maxlifetime but share the same place for storing the session data then the script with the minimum value will be cleaning the data. In this case, use this directive together with session.save_path.

For more refer to this post.

like image 20
LF00 Avatar answered Oct 13 '22 12:10

LF00