Page 1 of 1
prevent variable from incrementing on browser refresh
Posted: Wed Jun 01, 2005 7:00 pm
by uniballer
Is there a way to prevent a variable from incrementing by it's last given value when the browser is refreshed?
Posted: Wed Jun 01, 2005 7:11 pm
by Spaceboy
You could check to see what page is referring you to the current page using javascript (document.referrer). That's the way I've done similar things. If the referrer is the same as $PHP_SELF, then do not increment because the page was refreshed.
I don't know if there is a PHP way to get the page referrer, does anyone else?
Posted: Wed Jun 01, 2005 7:35 pm
by uniballer
What I'm doing is updating a textarea object on the same form while populating a variable, a number of times before acutally submitting the form. I have no other page that is referring me to where I'm at.
Posted: Wed Jun 01, 2005 8:17 pm
by Skara
Then you just get to the page you're at through typing it in the address bar? What ^ means by referrer is the page that is linked to the one you're on. Just so we're clear.
Posted: Wed Jun 01, 2005 9:00 pm
by uniballer
I got the referrer part.
The thing is, is that the 'referrer' page is only a link to the page I have my variable on. Nothing is being passed to this page, just a static link.
Posted: Wed Jun 01, 2005 9:03 pm
by Grim...
Add a hidden variable of 'increment' to the form:
Code: Select all
<input type="e;hidden"e; value=1 name="e;increment"e; />
Now, only increment the value if $increment is true.
This won't help if people hit refresh then 'yes' to the resending of form values, though...
Posted: Wed Jun 01, 2005 9:06 pm
by Grim...
In answer to Spaceboy, here is one way PHP can get the page referer:
Code: Select all
$referef = getenv('HTTP_REFERER');
Posted: Wed Jun 01, 2005 9:06 pm
by hawleyjr
why don't you just use sessions?
Posted: Wed Jun 01, 2005 9:14 pm
by uniballer
I am actually using a SESSION variable, here is what my code looks like.
<?php
$_SESSION['points'] = (($y_pts['points'])*($_POST['decks_txt'])) + $_SESSION['points'];
?>
I create a SESSION, but because the form may not be ready to submit (because there may be more items to add to this textarea), I use the current contents of the SESSION to further update it's value. But refreshing the page resends the data to the variable and in turn to the SESSION aswell. I was hoping there was rather easy way out of this one.
Posted: Wed Jun 01, 2005 9:23 pm
by Skara
Grim... wrote:In answer to Spaceboy, here is one way PHP can get the page referer:
Code: Select all
$referef = getenv('HTTP_REFERER');
better is $_SERVER['HTTP_REFERER']; *shrugs*
Posted: Wed Jun 01, 2005 9:28 pm
by John Cartwright
DO NOT CROSS POST.
Original thread can be found at
viewtopic.php?p=177011