Trouble with PHP session_register and setcookie with MAMP

I am following the php tutorial in
Even if I set my Safari browser(since I’m using a MAC and therefore MAMP local hosting) to always accept cookies, I still have trouble using session_register or setcookie to work properly. E.g.
For the setcookie problem:

<? setcookie("my_colour_eyes", "green"); echo " Click here to go to the next page"; ?>

//Above is one file
//Below is the ‘read_from_cookie.php’

<? echo "My eyes are".$my_colour_eyes; ?>

But when I open the file in MAMP using Safari or Firefox I only get “My eyes are”
For the session_register function…when I use Firefox to open it, it doesn’t work properly as well.
Here is my code

<? session_start(); $my_favourite_colour="blue"; session_register("my_favourite_colour"); echo " Click here to go to the next page"; ?>

//Above is one file
//Below is the ‘show_session_var.php’ file

<? session_start(); echo "My favorite colour is: ".$my_favourite_colour; ?>

Am I missing something? I have also tried enabling register_global in the php.ini file, but that doesn’t seem to work either…plus ppl have advised against enabling that for security reasons…
Please help me go over this roadblock…thank you…

echo “My eyes are”.$my_colour_eyes;
should be:
echo “My eyes are”.$_COOKIE[‘my_colour_eyes’];

echo "My favorite colour is: ".$my_favourite_colour;
should be:
echo "My favorite colour is: ".$_SESSION[‘my_favourite_colour’];

and turn off globals, you shouldn’t have them on for security reasons :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service