Discussion:
unset($_GET['i'])
Bill
2008-09-04 19:47:31 UTC
Permalink
Hi

given page1 has a list of goods and sends $i as a variable into a link
to page2, ie, <a href="page2.php?i=3">send</a>

Page2 adds the items recieved in an array.

In page2 how can I unset the $_GET['i'] so that if I press F5(refresh)
it doesn't add the same item to the array ?

I tried unset($_GET['i']) but no success.

Thanks
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Dan Shirah
2008-09-04 19:55:51 UTC
Permalink
Hi
given page1 has a list of goods and sends $i as a variable into a link to
page2, ie, <a href="page2.php?i=3">send</a>
Page2 adds the items recieved in an array.
In page2 how can I unset the $_GET['i'] so that if I press F5(refresh) it
doesn't add the same item to the array ?
I tried unset($_GET['i']) but no success.
Thanks
How about just adding a simple counter on your page.

if ($count == "0") {

Run through your script
At the end update the variable: $count == "1";

} else {

Don't run throught script because the value has already been added

}
Bill
2008-09-04 20:23:23 UTC
Permalink
Post by Dan Shirah
How about just adding a simple counter on your page.
That's what I do but that "counter" resets when you press F5 and is not
functionnal.

Why $_GET['i'] doesn't unsets ?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Boyd, Todd M.
2008-09-04 20:28:31 UTC
Permalink
-----Original Message-----
Sent: Thursday, September 04, 2008 3:23 PM
Subject: Re: [PHP] unset($_GET['i'])
Post by Dan Shirah
How about just adding a simple counter on your page.
That's what I do but that "counter" resets when you press F5 and is not
functionnal.
Why $_GET['i'] doesn't unsets ?
Your page URL has ?i=asdf in it. As such, $_GET['i'] is being set every time you refresh that particular URL. Unsetting $_GET['i'] will only erase the variable for that instance of that PHP script. As soon as you refresh, you are calling a new instance of that PHP script and assigning $_GET['i'] the value "asdf" (or whatever).

If clearing that value on refresh is truly important to you, then don't use GET.


Todd Boyd
Web Programmer
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Bill
2008-09-05 00:15:07 UTC
Permalink
Post by Boyd, Todd M.
Post by Bill
Why $_GET['i'] doesn't unsets ?
Your page URL has ?i=asdf in it. As such, $_GET['i'] is being set every time you refresh that particular URL. Unsetting $_GET['i'] will only erase the variable for that instance of that PHP script. As soon as you refresh, you are calling a new instance of that PHP script and assigning $_GET['i'] the value "asdf" (or whatever).
Not using GET means rewriting all the pages.
Ok then I'll use a session variable.


Thanks you all.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Dan Shirah
2008-09-04 20:34:44 UTC
Permalink
Post by Bill
Post by Dan Shirah
How about just adding a simple counter on your page.
That's what I do but that "counter" resets when you press F5 and is not
functionnal.
Why $_GET['i'] doesn't unsets ?
Are you saving the array to a database once it is created? If not, wouldn't
the array be recreated once someone refreshes the page as well?
Wolf
2008-09-04 20:27:43 UTC
Permalink
Post by Bill
Post by Dan Shirah
How about just adding a simple counter on your page.
That's what I do but that "counter" resets when you press F5 and is not
functionnal.
Why $_GET['i'] doesn't unsets ?
Because you get a new i from the URL, hence the GET

What you can do is set a session variable when you GET the first i, then just check and if the session variable is present, you don't process the next time you GET i.

Wolf
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Micah Gersten
2008-09-04 20:29:11 UTC
Permalink
The $_GET array comes from the URL which is resent every time someone
hits F5. unset works on the server, not on the browser. You could
capture it, add it to the session and then redirect without it in the URL.

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com
Post by Bill
Post by Dan Shirah
How about just adding a simple counter on your page.
That's what I do but that "counter" resets when you press F5 and is
not functionnal.
Why $_GET['i'] doesn't unsets ?
--
Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Continue reading on narkive:
Loading...