Pergunta

If I submit a form to a php page using post, can I use those post values on a page that I arrive at by using the header('location: ...php') redirect?

Example:

<form action="welcome.php" method="post">
   Name: <input type="text" name="name"><br>
   E-mail: <input type="text" name="email"><br>
   <input type="submit">
</form>

On welcome.php, if I do header("Location: welcomBack.php") can I still access $_POST['Name'] and $_POST['E-mail']... (from welcomeBack.php)?

Foi útil?

Solução

NO, you can't. Redirect to another page will mean to be in another page and no $_POST value nor $_POST array will be avaiable. In other hand you can still pass values throw the link itself and have available in the other page. For example

header('location: other.php?data=one');

So in the other page you can use

echo $_GET['data'];
//print one

As sidenote i would add you can redirect to another page with a form action and then have all values available in the other page in the $_POST array

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top