Clear POST data

Hi

How can I clear the POST data after processing them?  So that when the users press the REFRESH button, the data isn't resend?



Ramses (x_terminat_or_3)
LVL 2
x_terminat_or_3Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

alexmayCommented:
You can store the POST data in a session variable and then call your page again without adding the post data.
Or put another way, you have the page call itself.
Let me know if that is not clear enough.
0
x_terminat_or_3Author Commented:
It isn't...
0
Diablo84Commented:
To clear post data:

$_POST = array();

but that will not prevent the behaviour you are seeing of the browser trying to resend the data,

You need to point the form to a seperate page (eg. <form action="process.php.... ) then in that file you would have

<?php
//process form data
header("location: destination_page.php");
exit;
?>

where destination_page.php is the page the user will be redirected to once the data has been processed. This will be invisible to the user, it will appear they have been sent straight to the destination page without the middle man page being present and will prevent the browser tring to resend the data on refresh or hitting the back button.
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

x_terminat_or_3Author Commented:
Yeah but that means that the destination page has to be static

I already saw sites implementing a way that clears POST data but keeps them somehow in memory
0
Diablo84Commented:
sessions as alexmay mentioned.

Same process, you have your page process.php

<?php
session_start();

$_SESSION['variable_name'] = $_POST['input_field_name'];
$_SESSION['another_variable'] = $_POST['another_field_name'];
//etc

header("location: destination_page.php");
exit;
?>

then on your destination page you can access the data that was assigned to the post array using echo $_SESSION['variable_name'];

Note: you must also have session_start(); at the top of the destination page to initialize the session data (before any output)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Diablo84Commented:
or i suppose the more automatic method would be:

foreach($_POST as $key => $value) $_SESSION[$key] = $value;

Which will assign every post key and value to a session var.
0
x_terminat_or_3Author Commented:
I think I like this better ;)
0
Diablo84Commented:
:)

If you have any problems with it feel free to post back.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.