Jnanada Prasad Paul
Jnanada Prasad Paul

Reputation: 33

Cookie can not accessed

I am facing a another problem. I built a project in php. the url is like 'www.mysite.com' I create a cookie using setcookie() method in example1.php page which is under root directory and the path of the page is ... www.mysite.com/in/example1.php

Now i want to retrieve the value of the cookie in the page 'indix.php' whose url is www.mysite.com/index.php that is outside the folder 'in'.

But the cookie is not found in this index.php page. i use print_r() but no cookie found.

What the wrong i have done? Please help me.

Upvotes: 1

Views: 83

Answers (2)

Hristo Petev
Hristo Petev

Reputation: 309

When you set the cookie

setcookie ( string $name [, string $value [, int $expire = 0 [, string $path [, string $domain [, bool $secure = false [, bool $httponly = false ]]]]]] )

you have to set the $path parameter to '/' this way it will be visible everywhere in your page. Also check your $expire parameter.

Upvotes: 0

Felix Weelix
Felix Weelix

Reputation: 382

http://php.net/manual/en/function.setcookie.php

Scope of cookie is 4th variable (the "path") - defaults to current path. Sounds like you need to set it to server root directory, or '/'.

setcookie('mycookie', 'myvalue', 0, '/');

Upvotes: 2

Related Questions