Accessing Joomla Cookies via Sub-Domains

How to

 

 

The solution is to set the session for your whole domain and/or site. It applies if you’re trying to access the session data outside of joomla scope. For example, if your joomla site is located on http://example.com/joomla/ and your other site on http://othersite.example.com/ then the cookie holding the session id is not transmitted from joomla to the other site. To modify this behaviour, use session_ set_ cookie_ params before every session_start() (I don’t know joomla very well, but you should have to add only a few lines of code). Use it this way:

session_set_cookie_params(86400,'/','.example.com');

86400 is the lifetime of the session, set it to what you prefer (86400 is one day). ‘/’ is the path of the cookie. It means that if your joomla site is located on http://example.com/joomla/ , the session cookie will still be sent if the user accesses http://example.com/ .

‘.example.com’ is the domain. Note the dot at the beginning, it’s very important. It says that the session cookie will be sent on any subdomain of example.com. If you don’t put it, the cookie will be sent only for addresses starting with http://example.com/ .

This should solve your problem, unless you are trying to access the session data from another domain. If it’s the case, leave a comment here, I’ll see if I cand find something.

Leave a Reply