How to set the php session time out, I'm trying like below, but I dont think it works
ini_set("session.gc_maxlifetime", 600);
How to find out whether a php session exists or expired using ajax (javascript)?
Regards
Use the unset() Function to Set the Session Timeout in PHP This method stores the session in an array. We can use the associative array to store the session name and the session start time. We can use the time() function to get the current time.
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.
For #1 use session_set_cookie_params()
. To expire after 600 seconds
session_set_cookie_params(600)
(note unlike the regular setcookie
function the session_set_cookie_params
uses seconds you want it to live, it should not be time() + 600
which is a common mistake)
For number 2 just make a small script called through AJAX:
<?php
session_start()
if( empty($_SESSION['active']) ) {
print "Expired"
}
else {
print "Active"
}
?>
On the Javascript side (using JQuery)
$.get('path/to/session_check.php', function(data) {
if( data == "Expired" ) {
alert("Session expired");
} else if (data == "Active" ) {
alert("Session active");
}
});
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