Jump to content

help using header


knowram

Recommended Posts

I am using the header function to redirect a page. Which works great except when I want to send info to the redirected page.

 

example:

2 pages

a.php

b.php

 

 

If I am on page a.php which has a form on it and I hit submit there which normal refreshes back to its self but one of the check boxes are checked I have it redirecting to page b.php. The redirect works great but I would also like the rest of the variables that where submitted in the form to be accessed on page b.php.

 

Is that at all possible?

 

Thanks for the help

Link to comment
https://forums.phpfreaks.com/topic/53616-help-using-header/
Share on other sites

Why don't you just send the form on a.php to b.php? If that's out of the question, use sessions:

 

a.php

 

<?php

session_start();

if(isset($_POST["submit"])) { // If the form has been submitted
foreach($_POST as $var => $value) {
  $_SESSION[$var] = $value; // Now you have a $_SESSION array which is identical to the $_POST array
}
header("Location: b.php"); // Redirect the user
}

?>

 

b.php

 

<?php

session_start();

// From here on you can access all of the $_SESSION variables set in a.php

?>

Link to comment
https://forums.phpfreaks.com/topic/53616-help-using-header/#findComment-265007
Share on other sites

chigley beat me, but here is my post anyways.

 

Why not just set the form to submit to page b.php?

 

a.php

<form action="b.php" method="post">
<input type="text" name="var">
<input type="submit" name="submit">
</form>

 

b.php

<?php
$var = $_POST['var'];
echo $var;

?>

 

Link to comment
https://forums.phpfreaks.com/topic/53616-help-using-header/#findComment-265012
Share on other sites

I am not setting the form to submit to page b.php because I have two submit buttons in the same form and depending on which is used it either has to reload its self or go to page b.php

 

looks good however now on page b.php I am getting a Permission denied (13)  error.

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/53616-help-using-header/#findComment-265023
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.