Garethp Posted July 15, 2010 Share Posted July 15, 2010 For some reason I get different session values when I have www.domain.com to when I use http://domain.com. The both use the same sessions keys, but sessions set on one won't be set on the other, even if the domain.com is the same. Why is this so and how can I fix it? Quote Link to comment https://forums.phpfreaks.com/topic/207839-sessions-different-for-httpwwwdomaincom-and-httpdomaincom/ Share on other sites More sharing options...
unlishema.wolf Posted July 15, 2010 Share Posted July 15, 2010 if you are setting it to .domain.com then you shouldn't be having any problems. but if you set it to domain.com or www.domain.com the they will only work on the ones you set them too. but .doamin.com covers both. Quote Link to comment https://forums.phpfreaks.com/topic/207839-sessions-different-for-httpwwwdomaincom-and-httpdomaincom/#findComment-1086521 Share on other sites More sharing options...
Garethp Posted July 15, 2010 Author Share Posted July 15, 2010 Sorry, I'm not sure how to set the path for sessions. Can you link me? The PHP manual said that sessions_start has no arguments Quote Link to comment https://forums.phpfreaks.com/topic/207839-sessions-different-for-httpwwwdomaincom-and-httpdomaincom/#findComment-1086525 Share on other sites More sharing options...
unlishema.wolf Posted July 15, 2010 Share Posted July 15, 2010 session_set_cookie_params ( int $lifetime [, string $path [, string $domain [, bool $secure = false [, bool $httponly = false ]]]] ) lifetime Lifetime of the session cookie, defined in seconds. path Path on the domain where the cookie will work. Use a single slash ('/') for all paths on the domain. domain Cookie domain, for example 'www.php.net'. To make cookies visible on all subdomains then the domain must be prefixed with a dot like '.php.net'. so for example it would be session_set_cookie_params(0,"/",".domain.com"); this will make the session last until browser is closed. and work for both urls. Quote Link to comment https://forums.phpfreaks.com/topic/207839-sessions-different-for-httpwwwdomaincom-and-httpdomaincom/#findComment-1086535 Share on other sites More sharing options...
Garethp Posted July 15, 2010 Author Share Posted July 15, 2010 Ok, new problem. I have a Remember Me function that works well, but whenever I try to logout, it ONLY logs out of the http, even if I set the domain of the cookie (using setcookie) to .domain.com. Here's my code setcookie('Username', "Guest", $expire, '/', '.domain.com.au'); setcookie('Password', "Poke", $expire, '/', '.domain.com.au'); Now, it shows that cookie on the http version, but it doesn't change the www version, even if I run the script on the www one Quote Link to comment https://forums.phpfreaks.com/topic/207839-sessions-different-for-httpwwwdomaincom-and-httpdomaincom/#findComment-1086560 Share on other sites More sharing options...
unlishema.wolf Posted July 15, 2010 Share Posted July 15, 2010 okay so what you saying is when you set those cookies to login it only regs them on the domain.com.au and not the www.domain.com.au? Quote Link to comment https://forums.phpfreaks.com/topic/207839-sessions-different-for-httpwwwdomaincom-and-httpdomaincom/#findComment-1086568 Share on other sites More sharing options...
Garethp Posted July 15, 2010 Author Share Posted July 15, 2010 Exactly. It doesn't matter which one I use to set, it only sets on one of them Quote Link to comment https://forums.phpfreaks.com/topic/207839-sessions-different-for-httpwwwdomaincom-and-httpdomaincom/#findComment-1086571 Share on other sites More sharing options...
unlishema.wolf Posted July 15, 2010 Share Posted July 15, 2010 ok lets try this then. lets make it so that if someone goes to the www.domain.com.au it gets changed to domain.com.au. in your .htaccess file put the following. Options +FollowSymlinks RewriteEngine on RewriteCond %{http_host} ^www\.domain\.com\.au [NC] RewriteRule ^(.*)$ http://domain.com.au/$1 [R=301,NC] Now when you put that in dont forget to edit the domain.com.au to your actual website. and then try it out. you should get redirected when you type www.domain.com.au and go to domain.com.au. Quote Link to comment https://forums.phpfreaks.com/topic/207839-sessions-different-for-httpwwwdomaincom-and-httpdomaincom/#findComment-1086575 Share on other sites More sharing options...
Garethp Posted July 15, 2010 Author Share Posted July 15, 2010 I don't understand it, but for some reason it just started working. Thanks for the domain help, I probably just needed to let my browser adjust to that. Or some other excuse that works at 2am in the morning Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/207839-sessions-different-for-httpwwwdomaincom-and-httpdomaincom/#findComment-1086578 Share on other sites More sharing options...
unlishema.wolf Posted July 15, 2010 Share Posted July 15, 2010 That may have been it. Well hope it all works well for you. I actually got to go mow for money so I will be back later. Quote Link to comment https://forums.phpfreaks.com/topic/207839-sessions-different-for-httpwwwdomaincom-and-httpdomaincom/#findComment-1086584 Share on other sites More sharing options...
JasonLewis Posted July 15, 2010 Share Posted July 15, 2010 Or some other excuse that works at 2am in the morning I'm with ya, here in the land down under! Gotta love coding at 2am. Quote Link to comment https://forums.phpfreaks.com/topic/207839-sessions-different-for-httpwwwdomaincom-and-httpdomaincom/#findComment-1086612 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.