PHP Cookies

nike_guy_man's picture

They have: 840 posts

Joined: Sep 2000

Hello once again.
I'm writing a script that allows a user to log in at login.php3 and have his/her settings appear on all the other .php3 pages on the site.
How do I do this?
How do I read the contents of the cookies?
I'm thinking to use setcookie() but how do I get the contents of the cookie everywhere?
I can get the contents of the cookie on the same page, but not elsewhere.
Thanks!

Laughing out loud

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

Two ways...

1. just use the var name you specified when setting the cookie

<?php
//page 1
setcookie (\"TestCookie\", \"Test Value\");

//page 2
echo
$TestCookie;
?>

2. use the PHP's $HTTP_COOKIE_VARS
<?php
//page 1
setcookie (\"TestCookie\", \"Test Value\");

//page 2
echo $
$HTTP_COOKIE_VARS[\"TestCookie\"];
?>

Lots of goot examples and User Contributed Notes in the PHP docs: setcookie()

Mark Hensler
If there is no answer on Google, then there is no question.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.