views:

32

answers:

1

I have an HTML order form that collects info and then on submission passes that to a PHP form which sends an email. Then I have the PHP form forwarding to a PHP confirmation page.

  • I am using the POST method on my HTML form.
  • I am forwarding to the PHP confirmation page with header() after it sends the email.

Everything is working fine, but I need to know how to pass the variables along to the confirmation page. I can use them on the email page, but they are dropped on the page forwarding. I'm sure it's easy, but I have a lot to learn yet. :-) Do I have to create a file to store the variables, or can I pass them along?

I know I could display the confirmation page with the PHP page that sends the email (I did have it setup that way) but we have had users bookmark that page which will resend the order every time they visit that bookmark. So I'm separating the pages so if they bookmark the confirmation page it will at least not resend an order.

Make sense? Thanks for your help!

+2  A: 

You can keep the parameter sent in POST in session variables. This way on your second page, you can still access them.

For example on your first page :

<?php
session_start();

// ... //

$_SESSION['value1'] = $_POST['value1'];
$_SESSION['value2'] = $_POST['value2'];

header('Location: youremailpage.php');
die();

// ... //
?>

And on your second page :

<?php
session_start();

// ... //

$value1 = $_SESSION['value1'];
$value2 = $_SESSION['value2'];

// ... //
?>
HoLyVieR
I was wondering if sessions would be the answer. I'm not familiar with them but I'll learn. :-) Should I then end the session so the variables are no longer available? (there is no reason for them to be available after the confirmation is displayed)
Eric Wenger
@Eric After they are used, you can clear them if you don't use them afterward. That's fine.
HoLyVieR
Great, this is just what I needed. Thanks for the tutoring! Code is updated and working great! THANKS!
Eric Wenger
Good answer. I was thinking about session variables, but this is much more clear than I would have been.
Brian Stinar