Check if window is refreshed?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cbrian
Forum Commoner
Posts: 97
Joined: Sun Feb 27, 2005 12:29 pm

Check if window is refreshed?

Post 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
User avatar
Trenchant
Forum Contributor
Posts: 291
Joined: Mon Nov 29, 2004 6:04 pm
Location: Web Dummy IS

Post 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.
Post Reply