| Subcribe via RSS


passing session between subdomains

December 19th, 2007 | No Comments | Posted in php, server by dreamluverz




Few months ago i’ve been looking for ways how to do this. I’ve tried some things though but I need a better solution. Tonight I came across these sites on how to do it. I haven’t tried it yet coz I really don’t have time right now, i’m still packing my stuffs but I’m so eager to try it, for sure when I come back next year coz I need this code on the sites I’m working on.

<blockquote>

PHP configuration to set “session.cookie_domain” to “.mysite.com” (note the leading period) so that the session cookies are applicable across the entire domain.

ini_set(’session.cookie_domain’, ‘.example.com’);

</blockquote>

sources:http://www.phpbuilder.com/board/archive/index.php/t-10345127.html, http://www.dnforum.com/f181/keeping-session-variables-across-subdomains-thread-152857.html , http://www.webmasterworld.com/forum88/13145.htm

UPDATED: January 3, 2008

I just got back from my vacation and back to work again. :P

I’ve been trying out this session.cookie_domain for hours but can’t make it work. You may also find it in other forums or blogs that you need to set the cookie path but I didn’t try it coz according to some who tried it, it still didn’t do the trick.

Ssome says to use php_value session.cookie_domain as an alternative on .htaccess but I got internal server error 500. I’m not sure if it conflicts when the mod_rewrite i had on .htaccess so I just stick to ini_set() and try to make it work. I still believe in prayers so I did pray.

I tried checking the values cookie_domain, phpsessid on phpinfo(), defined ini_set(’session.cookie_domain’, ‘.example.com’); before calling session_start(), and restarted the browsers(tested on ie & ff) and now it works. Thanks God :)

UPDATED:  jan 7 ‘08

The session.cookie_domain doesn’t work in firefox when accessing url without www e.i. (http://domain.com)  so I removed  the preceeding dot ‘.’ on the domain value and now it works both for ie and firefox.

Tags: , , , , , ,