Sessions not working with www. sub domain.
Moderator: General Moderators
Sessions not working with www. sub domain.
Hey, whenever I go to my web site without the www. sub-domain(i.e. http://mywebsite.com) and log in then go to my web site with the www. sub-domain(i.e. http://www.mywebsite.com) I'm no longer logged in. I guess session variables don't work across sub-domains? How can I get session variables to work across sub-domains?
That's pretty much it. Thanks!
That's pretty much it. Thanks!
Last edited by JellyFish on Tue Nov 06, 2007 8:30 pm, edited 1 time in total.
I think I found it. Is it session_set_cookie_params()? If so, then I have some question about it.feyd wrote:Look in the session functions. There's only one that deals with cookies.
php.net says:
What if I don't want an lifetime set, nor a path? I'd just like to set the domain to mywebsites.com cause, hopefully, that would solve all my problems.void session_set_cookie_params ( int $lifetime [, string $path [, string $domain [, bool $secure [, bool $httponly]]]] )
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
~feyd's just trying to encourage you to use the PHP Manual 
Hint (right from php.ini):
Hint (right from php.ini):
Code: Select all
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =Okay I did a little research. Sense I do not recognize, for example, session.cookie_path to be a php object(because I assume all object to start with the $ character), I found that this would be for a .htaccess file?Chris Corbyn wrote:~feyd's just trying to encourage you to use the PHP Manual
Hint (right from php.ini):
Code: Select all
session.cookie_lifetime = 0 session.cookie_path = / session.cookie_domain = session.cookie_httponly =
So, the only way to set cookie parameters with php is through the session_set_cookie_params() function. The only problem with this is: I don't know much about the function as php.net doesn't explain as much about as I hoped.
So my questions about this function are: What argument should I pass for lifetime? I want the same lifetime that I get by default. Same with the path parameter, what should I pass it; what's the default; "/"?
Once I've had these questions answered then I'd make my way to that so, so special parameter("domain") and my problem would be solved, I'd die a happy adolescent.
PS: The only other option is editing an .htaccess file, but I'd might prefer doing it with php.
-
Mightywayne
- Forum Contributor
- Posts: 237
- Joined: Sat Dec 09, 2006 6:46 am
I don't want the sessions for my users to timeout. Would setting it to 1500 seconds make it time out in 25 hours?Mightywayne wrote:Set it to how many seconds you want it to be alive for. I personally do 1500 seconds; 25 minutes.
Not that it matters any, but I do suggest you choose the .htaccess option. www's so ugly.
Also, feyd seems to dodge around the answer a lot. Encouraging is nice, but so is the answer.
Other then that, I did some more searching(it's not like I don't use the php manual). I found ini_set() function. But the problem is, when I write this before I call session_start():
Code: Select all
ini_set("session.cookie_domain", ".mydomain.com");
session_start();
Also adding to my .htaccess file:
Code: Select all
AddType x-mapp-php5 .php
AddType x-mapp-php5 .php4
php_value session.cookie_domain ".mydomain.com"Re: Sessions not working with www. sub domain.
Sorry for bringing back such an old post, but it never had been resolved.
So I believed I learned a lot since when I first started this post so I'm going to give it another shot.
I set the coookie parameters like so:
So I did this and it doesn't seem to be having the effect I would like. It's not allow all sub-domains to share the same session variables(what I mean by session variables is the $_SESSION array).
What am I doing wrong?
So I believed I learned a lot since when I first started this post so I'm going to give it another shot.
I set the coookie parameters like so:
Code: Select all
session_set_cookie_param(0, "/", "mydomain.com");
What am I doing wrong?
-
Phoenixheart
- Forum Contributor
- Posts: 123
- Joined: Tue Nov 16, 2004 7:46 am
- Contact:
Re: Sessions not working with www. sub domain.
Having both http://www.domain.com and http://domain.com working at the same time is not a good idea imho anyway. I always choose to permanently redirect from http://www.domain.com to http://domain.com (or vice-versa).
Re: Sessions not working with www. sub domain.
Okay, that's what I had to, eventually, end up doing.
Thanks.
Thanks.
Re: Sessions not working with www. sub domain.
From the manual:I set the coookie parameters like so:
session_set_cookie_param(0, "/", "mydomain.com");
... It's not allow all sub-domains to share the same session variables...
The "/" makes cookies apply all to paths in the domain, but you need the "." to apply to all subdomainsCookie 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'.