user178167
user178167

Reputation: 43

Refresh with POST data

I am using the following php

header("Refresh: 0;url=thankyou.htm");

I want to add a hidden variable with that refresh so I must add something like.....

<input type=hidden name='varname' value="<?php echo $variable;?>">

How can I post the hidden variable to the refresh page?

How can these be combined?

Thanks

Upvotes: 0

Views: 2630

Answers (3)

Sarang
Sarang

Reputation: 51

Just iterate through the $_POST array and create a form with hidden inputs and a submit button

unset($_POST['refreshpage']);
echo "<form method='POST' action=''>\n";
foreach($_POST as $key => $val){
    echo "<input type='hidden' name='$key' value='$val'>\n";
}
echo "<input type='submit' value='Refresh Page' name='refreshpage'>\n";
echo "</form>";

Upvotes: 0

Riad
Riad

Reputation: 3870

Use session variable instead of hidden field.

session_start();

$_SESSION['var'] = $variable ; 

header("Refresh: 0;url=thankyou.htm");

in the thank_you page get the variable to retrieve...

EDIT: destroy session if required using session_destroy();

Upvotes: 0

Rasclatt
Rasclatt

Reputation: 12505

I don't know if it's secret enough but you could encrypt the variable and send as a $_GET:

header("Refresh: 0;url=thankyou.htm?varname=".base64_encode($_POST['varname']));

On the thankyou.htm page you would have to base64_decode() to get the value back.

Using a session will work behind the scenes for "most secret" as @Riad suggests.

Upvotes: 0

Related Questions