Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect with $_POST variable

How can I redirect to a page and add the $_POST variable with some info in it?

I know that with $_GET you have to append the variable to the URL like &var=foo

like image 897
Alex Avatar asked Nov 30 '22 17:11

Alex


2 Answers

session_start();

$_SESSION = $_POST;

Then your POST params will be available via $_SESSION.

like image 89
Doug Molineux Avatar answered Dec 10 '22 07:12

Doug Molineux


You can extract the data from $_POST, and append it to the redirection URL :

header('Location: http://www.yoursite.com/test.php?var=' . urlencode($_POST['var']));

If you have more parameters, see http_build_query(), to help building the query-string.


But note that this test.php page will be loaded by the browser using the GET method : the server cannot say to a browser to load another page using POST.

like image 20
Pascal MARTIN Avatar answered Dec 10 '22 07:12

Pascal MARTIN