homepage Welcome to WebmasterWorld Guest from 54.204.142.143
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Setting cookies in php from subdirectory
Cookies are set when run from root, but not when run in subdirectory
ikbenhet1




msg:1289376
 4:40 pm on Mar 25, 2003 (gmt 0)


When i run a php file that sets cookies from the root, the cookies are set.

When i run the same php file that sets cookies but from a subdirectory, the cookies are not set.

i use: setcookie("menuweg", trim($menuweg),time()+360000, "/");

How can i set the cookies from a subdirectory?

 

ikbenhet1




msg:1289377
 6:58 pm on Mar 25, 2003 (gmt 0)

still searching, i found this:

'If you want to send a cookie in a subdirectory that can be read by the whole domain set the path value to "/". '

Why does it not work then?

jatar_k




msg:1289378
 7:12 pm on Mar 25, 2003 (gmt 0)

are you setting more than one cookie?

ikbenhet1




msg:1289379
 7:23 pm on Mar 25, 2003 (gmt 0)

yes, about 6 cookies.

jatar_k




msg:1289380
 7:51 pm on Mar 25, 2003 (gmt 0)

all for the same domain? There's your problem, multiple cookies for the same domain cause problems. Setting all those cookies they are probably confusing the browser and/or script.

from
[php.net...]
Consider explode() [php.net] or serialize() [php.net] to set one cookie with multiple names and values

If you need to track that many vars I would consider using Sessions [php.net]

ikbenhet1




msg:1289381
 10:02 am on Mar 26, 2003 (gmt 0)

Thanks.

I've tried to do it with explode and set all values in 1 big cookie, but seems it's just too difficult for me, i just can't get it to work properly.

I did found a workaround, thanks to your advice:
I let the php file in the subdirectory redirect to the root, where the cookies are set, and let the root redirect back to the subdirectory. And it works ok, thanks again.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved