Multiple Domain Logins


Wonder how your login to mail.yahoo.com makes you logged into my.yahoo.com ?
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 http://mail.example.com/setcookie.php then the domain that is set is mail.example.com

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

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

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

Thats it. You have a multiple domain login code.

One Response to “Multiple Domain Logins”

  1. Mahdi (@MHR_IQ) Says:

    thanks

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s


%d bloggers like this: