clearing $_POST variables

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

Post Reply
User avatar
daven
Forum Contributor
Posts: 332
Joined: Tue Dec 17, 2002 1:29 pm
Location: Gaithersburg, MD
Contact:

clearing $_POST variables

Post by daven »

I am using $_POST variables in some of my scripts, and sending the info to a database. However, if a user reloads the page, the data is sent again (resulting in repeat entries).

Is there any way to destroy $_POST variables after use? Using unset() does not work, since reloading the page will re-initialize $_POST variables. I need to destroy the variable entirely (ie: use $_POST['id'], then get rid of it so subsequent calls will not work).
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

Post by oldtimer »

There must be but I just usually redirect them back to a certian page and make it go quick so they dont have a chance to do it. I never let it go more than 3 seconds. And alot of times only 1 second. However you could make a Thank you page and redirect all pages to that one with a 0 second delay as well.
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

i covered this in another topic but i can't seem to find it. when the user refreshes the page, the browser re-submits the POST variables to the server. (most browsers issue a warning about this.) so there is now way to erase them. you should do what oldtimer does, redirect to another page after you process the POST data.
User avatar
daven
Forum Contributor
Posts: 332
Joined: Tue Dec 17, 2002 1:29 pm
Location: Gaithersburg, MD
Contact:

Post by daven »

Ah well. The workaround I have been using is just to do a header("Location: ".$_SERVER['PHP_SELF']). It works fine (gets rid of $_POST vars). I was just wondering if there was a call to destroy the vars directly.

Thanks guys.
Post Reply