Page 1 of 1

Check if window is refreshed?

Posted: Tue Apr 26, 2005 4:53 pm
by cbrian
Is there anyway in PHP to check if the window has been refreshed?

I've been trying to use this function, but I discovered $_SERVER['HTTP_REFERER'] doesn't return that page if you refresh it, just the one you were to get to this page.

Code: Select all

function check_refresh($timestamp) {
$referer = $_SERVERї'HTTP_REFERER'];
$ref = explode('&',$referer); 
$oldstamp = explode('=',$refї1]);
$oldstamp = $oldstampї1];
if($oldstamp == $timestamp) {
echo &quote;Please do not refresh the page!&quote;;
}
}
EDIT: The HTTP_REFERER is something like http://www.website.com/KoD/game/game.ph ... $timestamp

Posted: Tue Apr 26, 2005 7:07 pm
by Trenchant
There are several easy ways. The way I commonly use is sessions. Just start a session at the top of the page. Then on the page you want protected do something like this:

Code: Select all

<?php
if ($_SESSION['check_refresh'] == '4S558FD7s2jDdjdf3') {
   echo "Error: Program Breach.";
}else{
   $_SESSION['check_refresh'] = '4S558FD7s2jDdjdf3';
}
?>

Then on the page you send the users after they have view the page simply destroy or change the session details.

If your system uses a popup you can simply close the popup.