checking if a "refresh" was done!

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
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

checking if a "refresh" was done!

Post by pelegk2 »

how can i check if the user pressed "F5" (refresh?)
beacuse for example if he has filled out data in a table and after i hhave aupdated he presses F5 the update will be done again!
how can i find thatout and even prevent it?
thnaks i nadvance
peleg
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

it can be stopped using javascript (the F5 press) however, there is no real sure-fire way of stopping it, theres too many ways a user could refresk, press return on address bar, press refresh icon, press f5 etc etc
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

well

Post by pelegk2 »

press return on address bar is not the same as press refresh icon, press f5 beacuse the first one is calling the page withought sending a form variables
where as for refresh icong/f5 it is!
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

if you press return on the address bar on a page that processes $_POST information, then it resends in the $_POST variables

at least it has for as long as ive been using browsers (a long time)

it may not technically be a refresh, but you are getting back exactly the same information on exactly the same page, so i would call it a refresh
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

malcolmboston wrote:if you press return on the address bar on a page that processes $_POST information, then it resends in the $_POST variables

at least it has for as long as ive been using browsers (a long time)
not since i have been using browsers it doesn't 8O :?

Hit refresh or F5 and it does, but not return in the address bar
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

lol, my bad, i was thinking $_GET even though i clearly stated $_POST :roll:
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

could the problem not be solved by...

Code: Select all

// at end of page
if (isset($_POST))
{
  unset($_POST);
}
then when it was refreshed, the post data would not be available?
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

My normal method of preventing update is

Code: Select all

if ($_REQUESTї'var']) {
  //Perform Update
  header(&quote;Location: url&quote;);
  exit;
}
Where url is the page again with any $_GET variables required to show the correct information.
No matter how the page is refreshed the update is not done again.
Post Reply