views:

47

answers:

3

I have problem in overwriting cookies value cross sub domains, a website running in ASP which is in www.domain.com and mobile site running in PHP with m.domain.com sharing same cookie

Cookie created in www.domain.com via asp as follow:

Response.Cookies("cookie_name")="value1"
Response.Cookies("cookie_name").Expires=DateAdd("m", 1, Date())
Response.Cookies("cookie_name").Domain = ".domain.com"
Response.Cookies("cookie_name").Path  = "/"
Response.Cookies("cookie_name").Secure = false

When i tried to overwrite the value in PHP (m.domain.com) as follow:

setcookie("cookie_name",'value2',time()+60*60*24*30, "/", ".domain.com",false);

the execution return true but when i check the cookie the value wasnt change still "value1"

also had tried to set via header

header("Set-Cookie: cookie_name=value2; path=/; domain=.domain.com; expires=".gmstrftime("%A, %d-%b-%Y %H:%M:%S GMT",time()+60*60*24*30));

but still no efects, any ideas? big thanks.

A: 

PHP and JavaScript sometimes can't work together aswell so I recognise the problem.

I don't know how much you depend on Javascript, but you could use it to set the cookie values(echo-ing "document.cookie = "=;expires=;path="; ").

It's dirty but at least there will be one common divider to worry about; not two.....

Deefjuh
A: 

I can't see any reason why this wouldn't work. I would first try clearing out your cookies in the browser and then retry to see if its works.

Kelly Copley
the problem only when try to overwrite, when i clear cookies and then setCookie works as normal
Ariel
A: 

Finally i made it work

header("Set-Cookie: cookie_name=value2; expires=".gmstrftime("%A, %d-%b-%Y %H:%M:%S GMT",time()+60*60*24*30)."; path=/; domain=domain.com");

Note the domain part (no dot), hope this helps others

Ariel