Forum Moderators: coopster

Message Too Old, No Replies

Cookies question

         

BobbyBudds

11:22 pm on Jul 14, 2005 (gmt 0)

10+ Year Member



I have 2 login screens. The first one is in root/mod/login.php and is set like this. setcookie(cookiename,'data',$cookiepath,$cookiedomain, $cookiesecure). The second cookie is for the same type of login but in directory root/member/mod/login.php and the cookie is set the same. I thought as long as the cookiepath is set to '/' then it will be accessible throughout the whole site from any file. Can anyone tell me what im doing wrong? thanks in advance.

coopster

11:43 pm on Jul 14, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, BobbyBudds.

It's not the path, it's the domain. Have a look at the setcookie [php.net] page for more information. Well, let's rephrase that, it could be a domain issue -- are you bouncing in and out of different subdomains?

BobbyBudds

2:21 am on Jul 15, 2005 (gmt 0)

10+ Year Member



no currently not subdomains, but in the future yes. I read about the domain is important if you are using subdomains if your cookies are going to work in both. Just a question, would this work? If i set a cookie like this (setcookie('cookiename','info',time()+3600, '/')) in directory root/forum/login.php and then when i try to access that cookie in root/mods/modname/page.php? Hopefully that made sense to you because that what my problem is, it wont read the cookie. Thanks

BobbyBudds

2:21 am on Jul 15, 2005 (gmt 0)

10+ Year Member



how would you test the domain if you were using localhost though?

coopster

11:09 am on Jul 15, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yes, your cookie should work in either directory if you are using root as the path.
Is the time set correctly on your pc?
Have you dumped the variables yet to see what is in them? Or better yet, hardcode the cookie parms for now until you are done testing.

In regards to subdomains on your localhost installation, you can setup <VirtualHost> containers in your Apache configuration and then you can edit your "hosts" file to add the different subdomains.