Jump to content

Recommended Posts

How can I detect if the page was refreshed?  I thought the following worked, however, after much head scratching, discovered it does not work for a POST request using the Chrome browser.  Thanks


<?php
$refresh=isset($_SERVER['HTTP_CACHE_CONTROL']) && $_SERVER['HTTP_CACHE_CONTROL'] === 'max-age=0';
echo(($refresh?'refresh':'not refresh').'<br>');
echo('$_GET<pre>'.print_r($_GET,1).'</pre>');
echo('$_POST<pre>'.print_r($_POST,1).'</pre>');
?>
<ul>
<li><a href="refresh.php?id=1">one</a></li>
<li><a href="refresh.php?id=2">two</a></li>
<li><a href="refresh.php?id=3">three</a></li>
</ul>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="text" value="hello">
<input type="submit" name="submit" value="submit">
</form>
Link to comment
https://forums.phpfreaks.com/topic/292952-detect-whether-the-page-was-refreshed/
Share on other sites

I don't quite understand... Do you trying do F5 protection?

 

I have a class that uses sessions to remember the browsers immediate previous state.

 

I use it to validate when JS is not available (no, I do not validate using JS, but POST the data using Ajax and if no errors, redirect client side to the next page).  Upon a non-ajax post request, I validate data, and if an error, store the error and redirect the page back to the form page.

 

Going to another page will clear the history as desired, but I don't wish to clear it if it is just refreshed with F5 or equal.

When you load the page check for some cookie value. If it's not there, set some cookie value;

If the page gets refreshed it will check for that cookie value again. If it is there, you know the page has been revisited/refreshed. You will have to delete the cookie once it is no longer needed. It will be reset every time they visit that page. 

When you load the page check for some cookie value. If it's not there, set some cookie value;

If the page gets refreshed it will check for that cookie value again. If it is there, you know the page has been revisited/refreshed. You will have to delete the cookie once it is no longer needed. It will be reset every time they visit that page. 

 

Set it to what?  A serialized GET or something?  I am not concerned whether they have ever been there, only that it was the last page.

 

 

I am not concerned whether they have ever been there, only that it was the last page.

Well, you have sessions. You can store the last page name/url in a session variable. Whatever page they visit, this session variable gets updated. Then you will always know what the last page visited was. 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.