How to save all POST information when redirecting to PHP?

header('Location: ' . $uri);

This will skip all the information $_POST.

+5
source share
6 answers

if u wants to transfer your data POSTto other pages (except the page action), use

session_start();
$_SESSION['post_data'] = $_POST;
+9
source

Do not use $ _SESSION as suggested. Session data is shared on all other pages, including other tabs. You can get unpredictable behavior if you use the same trick in several places on your site.

Unverified best code would be something like this.

session_start();
$data_id = md5( time().microtime().rand(0,100) );
$_SESSION["POSTDATA_$data_id"] = $_POST;
header('Location: ' . $uri."?data_id=$data_id");

On the next page you can get a previous post like this

session_start();
$post = array();
$data_key = 'POSTDATA_'.$_GET['data_id'];
if ( !empty ( $_GET['data_id'] ) && !empty( $_SESSION[$data_key] ))
{ 
    $post = $_SESSION[$data_key];
    unset ( $_SESSION[$data_key] );
}

, , , , .

+16

, POST.

(.. cURL ) , Javascript/ .

, @diEcho, , : .

+2

, GET.

You can save your POST at SESSIONS or encode it in GET (as a query string)

+1
source

You can save message data in a session, redirect it, and then return it from the session.

session_start();
$_SESSION['POSTDATA'] = $_POST;
header('Location: ' . $uri);

Then, in the PHP file for the new location, extract the post data as follows:

$_POST = $_SESSION['POSTDATA'];
+1
source

I use my simple method.

Think very logical! For example, if you use the text attribute that you want to keep, you can use:

<?php $textvalue = $_POST['textname']; ?>
<input type="text" name="textname" value="<?php echo $textvalue; ?>" />

<br />

//And if you want to use this method for a radio button, you can use:
<?php if(isset($_POST['radio1']){
  $selected = "selected";
}  ?>
<input type="radio" name="radio1" <?php echo $selected; ?> />
-2
source

All Articles