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.php:2) in public_html/order/thanks.php 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"]=$dollar;
$_SESSION["cents"]=$cents;
$_SESSION["item"]=$item;


here is the thanks.php page:

session_start();

$_SESSION["email"]=$email;
$_SESSION["dollar"]=$dollar;
$_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.
Donnie WalkerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
session_start(); must be at the top of Every Single page in the session.  It doesn't just 'start' the session, it renews it and identifies the $_SESSION variables.  If you try to set $_SESSION variables before starting the session, they don't go anywhere.

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
Dave BaldwinFixer of ProblemsCommented:
And on thanks.php, you have to reverse the order of variable assignment to get the data from the $_SESSION variables to the 'regular' variables.

$email = $_SESSION["email"];
$dollar = $_SESSION["dollar"];
$cents = $_SESSION["cents"];
$item = $_SESSION["item"];

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Donnie WalkerAuthor Commented:
Thanks Dave!
Dave BaldwinFixer of ProblemsCommented:
You're welcome, glad to help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.