cookie reading

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

cookie reading

Post by itsmani1 »

Hi

I wanted to see if cookie is set or not...

For example i have site example.com and there is directory named member in it

i set a cookie in that directory i.e. example.com/cookie

can i read and/or access that cookie value from example.com ?

if i can please tell me how...

my domain name:
example.com
i set a cookie at:
example.com/member

and now i wanted to read it from example.com
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: cookie reading

Post by superdezign »

Cookies are domain-specific. Any cookie made on example.com at any directory will belong to example.com. In PHP, you can access your domain's cookie by using the $_COOKIE superglobal array.
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Re: cookie reading

Post by itsmani1 »

you mean like :

Code: Select all

print($_COOKIE);
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Re: cookie reading

Post by itsmani1 »

currently i am at example.com/members

I set a cookie "test_cookie"

I can access it here but i wanted to access it when i go back to example.com

I tired it this way:

Code: Select all

<?PHP
print_r($_COOKIE);
?>
but it's not showing my anything

but when i go to example.com/members and use same code i get value
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: cookie reading

Post by superdezign »

Are you sure that you are creating the cookie correctly? You haven't shown the code that you use to set your cookie.

http://php.net/cookies
Post Reply