prevent variable from incrementing on browser refresh
Moderator: General Moderators
prevent variable from incrementing on browser refresh
Is there a way to prevent a variable from incrementing by it's last given value when the browser is refreshed?
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?
I don't know if there is a PHP way to get the page referrer, does anyone else?
Add a hidden variable of 'increment' to the form:
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...
Code: Select all
<input type="e;hidden"e; value=1 name="e;increment"e; />This won't help if people hit refresh then 'yes' to the resending of form values, though...
In answer to Spaceboy, here is one way PHP can get the page referer:
Code: Select all
$referef = getenv('HTTP_REFERER');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.
<?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.
better is $_SERVER['HTTP_REFERER']; *shrugs*Grim... wrote:In answer to Spaceboy, here is one way PHP can get the page referer:Code: Select all
$referef = getenv('HTTP_REFERER');
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact: