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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.