Ok so sometimes we need to carry the sessions across all of the subdomains. So this is one thing you can do in your .htaccess file.

php_value session.cookie_domain “.domain.com”

Incase of cookies you most probably know what to do but as a reminder here it is.

setcookie(”TestCookie”, $value, time()+3600, “/~rasmus/”, “.example.com”, 1);

Notice the .domain.com in both cases , this lets the cookies be accessable from all subdomains.

Now thats all goody goody BUT when it comes to having a domain span across multiple servers , like lets say you host the main domain.com on server 1 and the subdomain abc.domain.com on server 2, the session id will be carried across just fine if you use the .htaccess method BUT whatever is inside the session will NOT be available across both servers. The reason is pretty simple , lets say you begin your session on server 1 , you store some data in the session and it is stored in the domain.com session save directory BUT when you goto abc.domain.com , you cannt access the data stored in the session save directory from server 1. So basically this doesnt help much across multiple servers, does it?

Ok so what can we do about this?

Now after some thinking a probable solution was to use the database and keep the session data in there. But i didnt like the extra load it was putting on the MySql server.

So after alot of thinking I devised a little plan for this , now there is one thing we do have as common on both ends , we have the session id , now you can integrate a crypt / decrypt mechanism with the session id acting as the key, to solidify it further , add some more characters to the session id and use that as a key. Then send the session data in the query string.

something like this:

$key = “somethinghere”.session_id() . “somethingmore”;

Use the above generated key on server 1 to generate the query string and decode it with the same key on server 2 and vice versa if need be.