0

I have been trying to detect the page reload/refresh in php using both Xampp and Apache 2.2.22 using PHP. It workd fine in Xampp but not using Apache 2.2.22( on my UNIX environment)

<?php
// Start the session
    session_start();
    $RequestSignature = md5($_SERVER['REQUEST_URI'].$_SERVER['QUERY_STRING'].print_r($_POST, true));

    if (isset ($_SESSION['LastRequest']) && $_SESSION['LastRequest'] == $RequestSignature)
    {
          echo 'This is a refresh.';
    }
 ?>
parul71625
  • 193
  • 2
  • 4
  • 14
  • Can you elaborate a little ? It's kind of confusing because `xampp` uses apache server. – imrealashu Oct 10 '16 at 05:14
  • Yes. It uses Apache Server. So when I execute the above code using Xampp as my Apache Server, it works fine. But when I try to use Apache server (Apache 2.2.22) in my UNIX environment, it does not work – parul71625 Oct 10 '16 at 05:16
  • Xampp comes with some predefined settings which might be the stuff you should look into. But I'd love to know what are you trying to create which you're doing these ? – imrealashu Oct 10 '16 at 05:22
  • Possible duplicate of [PHP: Detect Page Refresh](http://stackoverflow.com/questions/4290230/php-detect-page-refresh) – Jigar Oct 10 '16 at 05:54

1 Answers1

1

try dis

$pageWasRefreshed = isset($_SERVER['HTTP_CACHE_CONTROL']) && $_SERVER['HTTP_CACHE_CONTROL'] === 'max-age=0';

if($pageWasRefreshed ) {
   //do something because page was refreshed;
} else {
   //do nothing;
}
Bakhtawar GIll
  • 407
  • 5
  • 16