WWW responseHeaders not giving me cookie in web-player, but does in editor

I know this feature is undocumented except in the release notes, but it also appears to be buggy.

My PHP uses setcoookie() to set a cookie, of course, and when I'm running the editor, I can get it no problem. However, in web player builds, this header is not there, as if it didn't exist. I see other headers there, but not the SET-COOKIE one.

Try

for (var r in www.responseHeaders)
  Debug.Log(r);

What gives?

The problem could be that the cookie is still set. The Webplayer does the www communication through the browser. A webserver will set a cookie only if needed. Since the cookie is transmitted with each www call there's no need for the server to set the cookie.

You can use Application.ExternalEval to get the cookie information from `document.cookie`. Furthermore the responseHeaders have a bug. They made it a Hashtable which seems quite handy in the first place but some HTTP header fields (like Set-Cookie) can be added multiple times. The Hashtable will only keep one of them... Some servers merge all Set-Cookies into one field but not all.

If you're not sure if the field is included or not i recommend WireShark ;)


edit

Well, just put this script on a GameObject and name the object "MyObject" (or what ever)

var cookieStr : String;
var isLoaded = false;
function UpdateCookieString()
{
    isLoaded = false;
    Application.ExternalEval(
        "var unity = unityObject.getObjectById(\"UnityContent\");"+
        "unity.SendMessage(\"MyObject\", \"OnGetCookie\", document.cookie);"
    );
}

function OnGetCookie(cookie : String)
{
    cookieStr = cookie;
    isLoaded = true;
}

Just make sure that the SendMessage function can find your GameObject. See the browser communication docs for more information.

ps. you can insert the object name directly into the eval string:

"unity.SendMessage(\"" + gameObject.name + "\", \"OnGetCookie\", document.cookie);"