Passing data between pages with $_SESSION
I am having difficulty with this. To test I made two simple pages passing data from one to the next.
Page one.
<?php
session_start();
echo session_id();
// Set session variables
$_SESSION["favcolor"] = "green";
$_SESSION["favanimal"] = "cat";
echo "Session variables are set.";
Page two.
session_start();
echo session_id();
// Echo session variables that were set on previous page
echo "Favorite color is " . $_SESSION["favcolor"] . ".<br>";
echo "Favorite animal is " . $_SESSION["favanimal"] . ".";
Result:
23349bac5fa1be24474c67a02d4cbc7b
Favorite color is .
Favorite animal is .NULL
The session ID is the same on both pages. What else should I be checking?
Thank you