Page 1 of 1

Subdomain problems [Solved]

Posted: Mon Mar 22, 2010 1:21 pm
by echofool
Hey, i have had a massive problem with my business site which is causing delays and money :(!!

I have a login script which creates a session ($_SESSION['Current_User']) which holds the User's ID.

Now i have tried many ways to solve my problem but no matter what i do, this session does not remain set when i use it on a subdomain when created on my main domain.

For example:
http://www.mydomain.com/login.php - SESSION set
http://www.subdomain.mydomain.com/index.php - Notice: Undefined index: Current_User


The two sites have this at the top of the script which i read was suppose to be the solution but its not working for me:

Code: Select all

<?php
session_set_cookie_params(0, '/', '.mydomain.com');
session_start();
?>
*mydomain.com is for example purposes

I really need to fix this as its causing huge delays on my site development. Hope you can save me ! :(

Re: Subdomain problems

Posted: Mon Mar 22, 2010 3:30 pm
by Christopher
You should check if your setting change is actually working, or whether php.ini needs to be modified. You should also probably check if the problem is specific to one browser -- specifically IE6/IE7. And if all else fails you might want to try manually passing the session ID (or the setting for this).

Re: Subdomain problems

Posted: Mon Mar 22, 2010 3:36 pm
by echofool
Thank you for the reply. I edited my php.ini to state this:

Code: Select all

 
; Name of the session (used as cookie name).
session.name = PHPSESSID
 
; Initialize session on request startup.
session.auto_start = 0
 
; Lifetime in seconds of cookie or, if 0, until browser is restarted.
session.cookie_lifetime = 0
 
; The path for which the cookie is valid.
session.cookie_path = "/"
 
; The domain for which the cookie is valid.
session.cookie_domain = .maindomain.com
 
domain edited out on purpose, replaced with "maindomain"

How do i check if the setting change is working? And i will check other browsers and report back on what occurs.

Re: Subdomain problems

Posted: Mon Mar 22, 2010 3:39 pm
by AbraCadaver
It looks fine, but I've read that you must set the session_name() before session_set_cookie_params(). Try:

Code: Select all

session_name('SOMENAME');
session_set_cookie_params(0, '/', '.mydomain.com');
session_start();

Re: Subdomain problems

Posted: Mon Mar 22, 2010 3:51 pm
by echofool
Hmm i get different results on IE to FF.

Works perfect on FF (Thank you SO much for that!) :)

But IE it does not allow it to work. Is there some kind IE hack required to get it to work on cross browsers?

Re: Subdomain problems

Posted: Mon Mar 22, 2010 7:14 pm
by Christopher
echofool wrote:But IE it does not allow it to work. Is there some kind IE hack required to get it to work on cross browsers?
I just looked at the Skeleton session code and found this that you might try:

Code: Select all

            if (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
                session_cache_limiter('must-revalidate');
            }
            session_start();

Re: Subdomain problems

Posted: Tue Mar 23, 2010 5:47 pm
by echofool
May i ask what that does exactly?

Re: Subdomain problems

Posted: Tue Mar 23, 2010 6:24 pm
by Christopher

Re: Subdomain problems

Posted: Fri Mar 26, 2010 7:39 pm
by echofool
Thanks i have it all working now :)