prevent variable from incrementing on browser refresh

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

Locked
uniballer
Forum Newbie
Posts: 7
Joined: Tue May 31, 2005 9:20 pm

prevent variable from incrementing on browser refresh

Post by uniballer »

Is there a way to prevent a variable from incrementing by it's last given value when the browser is refreshed?
User avatar
Spaceboy
Forum Newbie
Posts: 3
Joined: Tue May 31, 2005 2:10 pm

Post 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?
uniballer
Forum Newbie
Posts: 7
Joined: Tue May 31, 2005 9:20 pm

Post 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.
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post 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.
uniballer
Forum Newbie
Posts: 7
Joined: Tue May 31, 2005 9:20 pm

Post 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.
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Add a hidden variable of 'increment' to the form:

Code: Select all

<input type=&quote;hidden&quote; value=1 name=&quote;increment&quote; />
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...
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

In answer to Spaceboy, here is one way PHP can get the page referer:

Code: Select all

$referef = getenv('HTTP_REFERER');
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

why don't you just use sessions?
uniballer
Forum Newbie
Posts: 7
Joined: Tue May 31, 2005 9:20 pm

Post 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.
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post 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*
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

DO NOT CROSS POST.

Original thread can be found at viewtopic.php?p=177011
Locked