I have searched high and low for an answer to this. I have a site that plays long video files. I do not wish the user to timeout while watching a video, so I wanted to put a AJAX call on a timer that refreshes the session. I was told by many that doing anything with the session on the refresh page would be enough, but nothing is working. I have the php session expire set to 30 minutes. I would rather not increase this anymore.
Here is my jquery / AJAX call
//var time = 20000; // for live
var time = 10000; // for testing
// loop to handle refresh session
setInterval(function() {
// ajax call to get image
$.ajax({
url: 'refreshSession.php',
cache: false,
async: false,
type: "POST",
data: {},
success: function(){},
error: function(request, status, error){
alert('Login Session Error: ' + request.responseText + ' STATUS: ' + status + ' ERROR: '+error);
}
});
}, time);
The AJAX call is working great and loops correctly. Here is the refreshSession.php file which i need to keep the session alive.
<?php
include_once("configure.php");
// store session data
if (isset($_SESSION['userData']['userID']))
$_SESSION['userData']['userID'] = $_SESSION['userData']['userID']; // or if you have any algo.
?>
Note, that the configure.php file does call the session_start(); I was writing to a file the session id and other info and the correct information was being written. So I know this php file is reading the session variables.
However, after 30 minutes, I get logged out and the session is reset. Is there something I'm missing?