Donnie Walker
asked on
How do I pass and get a session in PHP?
I am trying to create a session on one page and then get them on another...but I'm getting this error:
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at public_html/order/thanks.p hp:2) in public_html/order/thanks.p hp on line 3
here is the code for creating the sessions:
$email = $_POST["element_6"];
$dollar = $_POST["element_13_1"];
$cents = $_POST["element_13_2"];
$item = $_POST["element_7"];
session_start();
$_SESSION["email"]=$email;
$_SESSION["dollar"]=$dolla r;
$_SESSION["cents"]=$cents;
$_SESSION["item"]=$item;
here is the thanks.php page:
session_start();
$_SESSION["email"]=$email;
$_SESSION["dollar"]=$dolla r;
$_SESSION["cents"]=$cents;
$_SESSION["item"]=$item;
mail("".$email."", "Order", "Thank you for your order!\n".$email."\nPaid: $".$dollar.".".$cents."\n" .$item."\n ");
mail("me@domain.com", "New Hosted Order", "".$email."\nPaid: $".$dollar.".".$cents."\n" .$item."\n ");
session_unset();
session_destroy();
I'm sure I'm doing alot wrong. For one thing the emails are empty. :)
Any help is appreciated.
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at public_html/order/thanks.p
here is the code for creating the sessions:
$email = $_POST["element_6"];
$dollar = $_POST["element_13_1"];
$cents = $_POST["element_13_2"];
$item = $_POST["element_7"];
session_start();
$_SESSION["email"]=$email;
$_SESSION["dollar"]=$dolla
$_SESSION["cents"]=$cents;
$_SESSION["item"]=$item;
here is the thanks.php page:
session_start();
$_SESSION["email"]=$email;
$_SESSION["dollar"]=$dolla
$_SESSION["cents"]=$cents;
$_SESSION["item"]=$item;
mail("".$email."", "Order", "Thank you for your order!\n".$email."\nPaid: $".$dollar.".".$cents."\n"
mail("me@domain.com", "New Hosted Order", "".$email."\nPaid: $".$dollar.".".$cents."\n"
session_unset();
session_destroy();
I'm sure I'm doing alot wrong. For one thing the emails are empty. :)
Any help is appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Dave!
You're welcome, glad to help.
Also, session_start(); like header() and cookies must be before anything on the page is sent to the browser including any white space. A single space before the opening <?php tag will cause an error.
Sessions are not terribly difficult but they are not what most people seem to think they are. And they are not as simple as people think they are. Their primary purpose is to identify $_SESSION data. http://php.net/manual/en/book.session.php