jquery - PhP Session does not refresh using AJAX -


i have searched high , low answer this. have site plays long video files. not wish user timeout while watching video, wanted put ajax call on timer refreshes session. told many doing session on refresh page enough, nothing working. have php session expire set 30 minutes. rather not increase anymore.

here jquery / ajax call

//var time = 20000; // live var time = 10000; // testing  // loop handle refresh session setinterval(function() {      // ajax call 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 working great , loops correctly. here refreshsession.php file need keep session alive.

<?php include_once("configure.php");  // store session data if (isset($_session['userdata']['userid']))     $_session['userdata']['userid'] = $_session['userdata']['userid']; // or if have algo. ?> 

note, configure.php file call session_start(); writing file session id , other info , correct information being written. know php file reading session variables.

however, after 30 minutes, logged out , session reset. there i'm missing?

don't know if got solution problem, facing issue , able resolved updating session cookie expiry time.

you need understand sessions maintained based on cookie set server. when main page loaded response header sets cookie expiry date. in order increase session expiry time, cookie expiry time needs increased.

set-cookie:phpsessid=xxxxxxxxxxxxxxx; expires=thu, 04-aug-2016 10:22:20 gmt; max-age=900;

so need update session cookie extended expiry time. use setcookie() accomplish this.

<?php session_start(); setcookie("phpsessid", session_id(), time() + ini_get("session.cookie_lifetime"));  include_once("configure.php"); 

you can use session_regenerate_id(). task of renewing session id expiry time. prevent session hijacking , session fixation.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -