Multiple Domain Logins

Wonder how your login to makes you logged into ?
It’s game of give and take with cookies.

When you save your authentication cookie, you generally set it with its name value pair like

setcookie(“auth”, md5($_POST[‘user’] . $_POST[‘userpass’] ));

If you take a look at the other post about Cookies
Note the parameter domain it is this parameter that you need to use.

By default the domain parameter that gets set is the domain on which the cookie is being set. So if you save the cookie on then the domain that is set is

So if you want a multiple domain login with , you need to set the cookie with the base domain name like this.

setcookie(“auth”, md5($_POST[‘user’] . $_POST[‘userpass’] ), time()+(3*3600), “/”, “”);

Note this tells the browser that the cookie should be used for all the sub domains of

Thats it. You have a multiple domain login code.


One Response to “Multiple Domain Logins”

  1. Mahdi (@MHR_IQ) Says:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: