Question

I have:

     mydomain.com (which is the portal of the game, global setting and stuff)
game.mydomain.com (which is the the actual game)

The problem is that I want to set a cookie that is available globally, on game.mydomain.net, mydomain.net (and whatever subdomain i'm going to create in the future).

I've been trying to set the cookie from another subdomain as I've read that subdomains can set cookies to parent domains but not vice versa (which is wierd and I guess I've read it wrong). Whatever, so I've done another account.mydomain.com (from which I'm making an ajax call form mydomain.net so the user can authenticate) and I'm using

setcookie('session', $value, time() + 2592000 (one month), '/', '.tribul.net');

Then, return the success message and refresh the main page on mydomain.net so it can read the new cookie value.. problem is, there's no cookie set. I've also been trying to set the cookie from mydomain.com (as .tribul.net) so it can be avaialable on all subdomains but it's available only on the main domain. What's wrong?

I need to connect all subdomains and the domain to the same cookie, TO BE NOTICED, I am setting the cookie in a backend file named process.php (placed in account.domain.com) as result of an ajax request.

Was it helpful?

Solution 3

I used Klaus Hartl's jquery cookie plugin in order to use my problem since I haven't been able to set up a global cookie from the ajax backend.

OTHER TIPS

Try this setcookie('session', $value, time() + 2592000 , '', '.tribul.net');

In php.ini:

session.cookie_path = /

session.cookie_domain = ".mydomain.com"

Set Cookie:

setcookie('session', $value, time() + 2592000, '/', 'mydomain.com');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top