Jump to content

Cre8asiteforums Internet Marketing
and Conversion Web Design


Photo

Php Cookies - Accessing From A Different Directory Problem

php cookies

  • Please log in to reply
1 reply to this topic

#1 hitchhiker

hitchhiker

    Ready To Fly Member

  • Members
  • 16 posts

Posted 25 January 2012 - 05:32 AM

Hi all,

My site creates cookies from a page in a directory called ...mysite.com/xbook which works fine - I can create/chnage/access them fine.

The problem I have is when I try to access those cookies from a different directory, in this case, the root directory

Can anyone tell me why this is happening and what to do?

Example

...mysite.com/xbook/create-cookie.php > create cookie call 'name' > cookie created > access cookie 'name' > works fine

...mysite.com/access-cookie.php > access cookie 'name' > returns that cookie does not exists!

TIA

#2 hitchhiker

hitchhiker

    Ready To Fly Member

  • Members
  • 16 posts

Posted 25 January 2012 - 06:08 AM

Solved it

Cookies can have an extra variable to say which directories they will be available to - the default it the dir from which they were created, for example:

setcookie('cookiename', $cookievalue, $expires); // sets cookie to be available only from the dir where it was created

setcookie('cookiename', $cookievalue, $expires, "/"); // sets cookie to be available throughout site



RSS Feed

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users