Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting rid of GET var upon page reload 2

Status
Not open for further replies.

Sleidia

Technical User
May 4, 2001
1,284
FR
Hi guys,

Is there a way to empty a $_GET variable after a page reload?

For example :


echo $_GET["msg"] // returns 2

// page reload

echo $_GET["msg"] // returns nothing

Thanks :)
 
It depends on what mechanism is doing the reload.

If your user is initiating the reload from the controls of the browser, there's not much you can do about it.

If your script initiates the reload, then it's possible to control this. After processing the input, your script could, for example, use a "Location" header to redirect the browser, stripping the value off the URL.

You could also use session variables to have your script know when it's being invoked multiple times in a row and ignore the input.



Want the best answers? Ask the best questions! TANSTAAFL!
 
Thanks sleipnir214,

It's a reload initiated by users that I'm trying to handle.

If your user is initiating the reload from the controls of the browser, there's not much you can do about it.

Why do you think so?

I've just tested this

Code:
$_SESSION["test"]++;
echo $_SESSION["test"];

... and the variable is incremented after every page reload from the browser.

Maybe I'm overlooking something ?
 
you could conditionalise the reload too. add a unique id into the query string and test the uniqueness for a subsequent refresh or press of the back button. this is the technique that i use for preventing a database update/insert on a reload of a page that contains a form.
 
When I said, "If your user is initiating the reload from the controls of the browser, there's not much you can do about it.", my statement assumed that you took no control at the server side.



Want the best answers? Ask the best questions! TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top