I am contemplating the structure for a new site. I would like to organize the site with sub domains as in

domain.com
subdomain1.domain.com
subdomain2.domain.com
subdomain3.domain.com

I understand that sessions are not passed from domain to domain or domain to subdomain. I did some searching and found out a few things. There doesn't seem to be much on the subject.

There is a setting in php.ini called session.cookie_domain. It is normally left set to "". However, you can set it to your domain and php will use that domain to store all sessions. This allows you to use sessions across domains.

This is fine if your domains are the only domains using php on the server. I happen to use an ISP so changing the ISPs php.ini file is not an option for me.

I can use ini_set() and temporarily modify the value of session.cookie_domain for the life of the script as in:

ini_set("session.cookie_domain", ".domain.com");

The . before domain.com is needed so that it is available to subdomains as well. This line needs to be called before session_start().

I could put this in an include file and call it from each page that uses a session.

I also read that ini_set() can be used in an .htaccess in the root directory of each domain, subdomain and directory where pages may use sessions. It would look something like:

php_value session.cookie_domain .domain.com

Setting the value in an .htaccess would be a lot easier than including ini_set("session.cookie_domain", ".domain.com");
on each page that uses sessions.


I have not tested any of these options as I am now gathering info in order to make a decision. I would appreciate any feedback on organizing the site, using subdomains, and passing session values from domain to domain. Is this more trouble than it is worth? Should I just use directories to organize the site?

Thanks in advance,
Blaine


-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to