Forums / All Other Contributions/Addons / Ajax requests and session timeouts

Ajax requests and session timeouts

Locked

Views: 1,520

Results 1 to 1 of 1
This thread is locked. New replies are disabled.
24 Dec 2010, 1:23 PM
#1
lumpylumpy avatar

lumpylumpy

New Zenner

Join Date:
Feb 2008
Posts:
27
Plugin Contributions:
0

Ajax requests and session timeouts

Hi, im am using 1.39h and al lot off customizations.
Every thing works just fine. Recently i have decided to use Jquery instead off Mootools and have made some customizing on the site with some ajax scripts: autocomplete, slide, pagination ...
As i said everything works.
The problem is with session timeouts, only when a customer is logged in. When a logged in customer stays on the same page for more then 24 minutes, the session times out, and he makes a ajax reguest on this page for any off the scripts i have he gets: a blank page for the autocomplete script and a "new whole site" instead of the div for pagination or slide, so practicly the customer gets a blank page or a new web page on the same page.
I have also installed "Automatic login" wich works just fine, but i still get the same errors when a customers is logged in, session times out and he makes a Ajax reguest
In all my Ajax scripts i use at the start

require('includes/application_top.php');

and at the end

require(DIR_WS_INCLUDES . 'application_bottom.php'); 

My solution: the Refresh plugin from Jquery, and this is the code:
Do not try this on a live site, your site structure might be different from mine, this is just an example

  1. load jquery, something like this
<script type="text/javascript" src="includes/templates/YOUR_TEMPLATE/jscript/jquery_min.js"></script>
  1. in templates/YOUR_TEMPLATE/commom/tpl_header.php
<?php
$page_refresh= false;
// don't display on checkout page:
  if (substr($current_page, 0, 8) != 'checkout') {
    $page_refresh= true;
  }
	if ($_SESSION['customer_id'] && $page_refresh == true) {
?>
<script type="text/javascript">
    // you can set a page refresh before dom ready
    $.refresh('refresh_json.php', 1380*1000);
    </script>
<?php }

this script calls for the page refresh_jason.php every 23 minutes if the customers in logged in and is not on any checkout page.
in this way i keep the session alive until the browser closes or the customer logs out.

  1. the code in refresh_jason is simple, just to load application_top.php and application_bottom.php
<?php
	require('includes/application_top.php');
?>
{
    "value":1
}
<?php
	require(DIR_WS_INCLUDES . 'application_bottom.php'); 
?>

If anybody has a better solution or an advice please let me know.
I dont know if this is the best way to do it, but for the moment it works for me.
I am opened to suggestions.

Best regards, Zoli

Merry Christmas to everyone !!!