Subdomain problems [Solved]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
echofool
Forum Newbie
Posts: 16
Joined: Mon Mar 22, 2010 1:15 pm

Subdomain problems [Solved]

Post 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 ! :(
Last edited by echofool on Fri Mar 26, 2010 7:40 pm, edited 1 time in total.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Subdomain problems

Post 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).
(#10850)
echofool
Forum Newbie
Posts: 16
Joined: Mon Mar 22, 2010 1:15 pm

Re: Subdomain problems

Post 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.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Subdomain problems

Post 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();
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
echofool
Forum Newbie
Posts: 16
Joined: Mon Mar 22, 2010 1:15 pm

Re: Subdomain problems

Post 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?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Subdomain problems

Post 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();
(#10850)
echofool
Forum Newbie
Posts: 16
Joined: Mon Mar 22, 2010 1:15 pm

Re: Subdomain problems

Post by echofool »

May i ask what that does exactly?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Subdomain problems

Post by Christopher »

(#10850)
echofool
Forum Newbie
Posts: 16
Joined: Mon Mar 22, 2010 1:15 pm

Re: Subdomain problems

Post by echofool »

Thanks i have it all working now :)
Post Reply