Tutorial :How to determine that an Ajax request is older than 5 minutes in PHP?



Question:

I am developing one site, and I want to ensure that Ajax requests which are older than 5 minutes are not executed. This means that I want to execute only fresh Ajax requests. How can I do this?


Solution:1

I supposed you could send a timestamp to the page as a JS variable, and then include it as part of the AJAX request - then compare the two

<script type="text/javascript">    // Using JQuery  $.post( 'process.php', {generatedTime:<?php echo time(); ?>}, function(data){} );    </script>  

And then, in process.php

<?php    if ( ( time() - $_POST['generatedTime'] ) > 300 )  {      // Request made over 5 minutes past generation of page  }  


Solution:2

Just look at $_SERVER['REQUEST_TIME'] .


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »