I am using a system to log in to a site that uses a number of subdomains of a subdomain. I have a development and live version of this system, however I am experiencing strange behaviour.

So, the setup is I have the following:

**Development environment:** 

* dev.mydomain.com
* sub1.dev.mydomain.com
* sub2.dev.mydomain.com

**Live environment:**

* live.mydomain.com
* sub1.live.mydomain.com
* sub2.live.mydomain.com

As part of the login process, I use the following line to set the cookie:

```
setcookie("LoggedIn", 1, 0,'/','.mydomain.com');

```

This all works fine and I can log in once and access everything, however I want to restrict it so that if I log in on the test system, then I am not logged in to the live system and vice versa.

I expected the solution to this to be:

```
setcookie("LoggedIn", 1, 0,'/','.test.mydomain.com');

```

and 

```
setcookie("LoggedIn", 1, 0,'/','.live.mydomain.com');

```

dependent on the system.

However, using this method I am able to log in to test.mydomain.com and live.mydomain.com independently but I am unable to log in to the sub-subdomains (sub1.test.mydomain.com, sub2. etc).

What am I doing wrong?