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

How to delete your whatsapp status

WhatsApp is a famous messaging App on the internet. Now Facebook is managing Whatsapp. Whatsapp is ...