Latest news
Home » CodeIgniter » How to Check Expired Sessions using jQuery Ajax and PHP

How to Check Expired Sessions using jQuery Ajax and PHP

We can achieve using the php and ajax.The following ajax call execute in every 10 seconds to check the status of session.If it expired the user redirected to seesionout page.

Ajax call in every 10 seconds

 

var check_current_session;
function CheckForCurrentSession() {
var strSession=”check_current_session=true”;
jQuery.ajax({
type: “GET”,
url: “check_current_session.php”,
data: strSession,
cache: false,
success: function(result){
if(result== “Y”) {
alert(‘Your session Already expired!’);
window.loaction(‘http://smarttips.in/sessionout.php’);
}
}
});
}
check_current_session = setInterval(CheckForCurrentSession, 10000);
PHP Code

session_start();
$sessionId = $_SESSION[“uid”];
if($sessionId == ”)
{
//session already expired
echo “Y”;
} else {
//session not expired yet
echo “N”;
}

 

You can also Download free script here

Leave a Reply

x

Check Also

Li fi

Wi-Fi is changing to High speed LiFi(Light Fidelity) Technology

As per the high demands of wireless communication data transfer, there are huge new technologies ...