Jump to content

Sessions Different for http://www.domain.com and http://domain.com


Recommended Posts

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?

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.

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.

 

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

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.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.