Jacob Brol
Jacob Brol

Reputation: 91

get cookie from different place on same domain

I'm trying to show the username that is given by a cookie on my forum. Now the problem is that i have no idea how to get a cookie that is on the same domain but on a different location. Like the script is in public_html and the cookie is in public_html/forum/

I tried the normal way :

    <?php
$mycookie = $_COOKIE["member_id"];  
if ( isset( $mycookie ) )  
   print "<p>The value in cookie - $mycookie</p>";  
else  
   print "<p>There is no value in cookie.</p>";  
?>

but that gives a result of

There is no value in cookie.

So is there a way that i can receive a cookie on a different place or is this not possible?

Upvotes: 0

Views: 69

Answers (1)

user2449612
user2449612

Reputation: 26

you need to store cookie for whole domain

setcookie("name", $example, time() + $time, '/', '.mydomain.com');

Upvotes: 1

Related Questions