-
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
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
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");
}
});