Jump to content

Refreshing page to keep session


dc_jt

Recommended Posts

Hi I am using the code below to refresh a page using javascript and ajax so that a user is never kicked out however I have had one user say they were kicked out. Is there any reason why their session may have expired? Could it be anything to do with their browser such as they dont have javascript enabled maybe?

 

function Ajax()
{
this.toString = function() { return "Ajax"; }

this.makeRequest = function(_method, _url)
{
	this.request = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP");
	this.request.open(_method, _url, true);
	this.request.send(_url);
}

this.checkReadyState = function(_id, _1, _2, _3)
{	
	switch (this.request.readyState)
	{
		case 1:
			if (_id != null) document.getElementById(_id).innerHTML = _1;
			break;
		case 2:
			if (_id != null) document.getElementById(_id).innerHTML = _2;
			break;
		case 3:
			if (_id != null) document.getElementById(_id).innerHTML = _3;
			break;
		case 4:
			return this.request.status;
	}
}
}

var oAjax = new Ajax();
var limit = 0;

function ajaxRefresh()
{
  if (limit==1)
  {
    //make background request
    oAjax.makeRequest('GET', '/sessionrefresh.php');
    limit = iMinutes * 60 + iSeconds;
  }
  else
  {
    limit--;
  }
  setTimeout("ajaxRefresh()",1000)
}

function beginAjaxRefresh()
{
  limit = iMinutes * 60 + iSeconds;
  setTimeout("ajaxRefresh()",1000)
}

var iMinutes = 5;
var iSeconds = 0;
beginAjaxRefresh();

Link to comment
https://forums.phpfreaks.com/topic/163779-refreshing-page-to-keep-session/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.