Welcome to WebmasterWorld Guest from 54.160.187.160

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

How to get the value of a Cookie?

How to get the value of a Cookie?

     
1:11 pm on Apr 14, 2008 (gmt 0)

Junior Member

10+ Year Member

joined:Mar 31, 2006
posts: 53
votes: 0


Hello,

How can i get the Value of a cookie?

Set the cookie:


setcookie("name", "value", time() - 3600);

Read the cookie:


(isset($_COOKIE["name"]))

I want to read the value not just the name.

Thanks in advance!

1:35 pm on Apr 14, 2008 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15755
votes: 0


try this to see what's in the cookie

echo '<pre>';
print_r($_COOKIE);
echo '</pre>';

6:21 pm on Apr 14, 2008 (gmt 0)

Full Member

5+ Year Member

joined:Dec 3, 2006
posts:257
votes: 0


$_COOKIE["name"] is the value
7:22 pm on Apr 14, 2008 (gmt 0)

Junior Member

10+ Year Member

joined:Mar 31, 2006
posts: 53
votes: 0


This was easier than i thought :P

So, is this correct?


if (isset($_COOKIE["name"]))
{
$content = $_COOKIE["name"];
}

(If a cookies is set, $content gets its value)
7:32 pm on Apr 14, 2008 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15755
votes: 0


yes, it should be correct

try it and see