Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 17511
  • Last Modified:

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)
0
x_terminat_or_3
Asked:
x_terminat_or_3
  • 4
  • 3
3 Solutions
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now