PHPSESSID with Unity

Hello everyone, I’m looking for some expert advice here.

Currently I have a working WWW call to login to a website

public IEnumerator Login()
	WWW www;
	WWWForm form = new WWWForm();
	form.AddField("player", username);
	form.AddField("password", password);
	www = new WWW(WEBSITE + "/authenticate.php", form);
	yield return www;
	isLoggedIn = true;

I already expected that if I wanted to visit another page (meaning another WWW call) via my app and logged in, I would have to store and send some session cookies.

The problem is that the website appears to rely on the ‘PHPSESSID’ cookie to stay logged in, which I cannot find in any WWW return variables (like responseHeaders).

Any ideas? Ill be checking back frequently if more information needs to be posted.

Usually the resposeHeaders should contain a Set-Cookie header. One problem could be that the website wants to set multiple cookies at once. In this case it’s not possible to get all cookies because Unity’s WWW class uses a Hashtable to store the response headers. By definition a HTTP response can include multiple Set-Cookie headers, but the Hashtable merge them into one and only the last one will survive.

If that’s the case, you can’t use WWW to get that cookie information. Try to use a C# class (WebRequest, HttpClient, …) to request the website.

I’ve posted a feedback long time ago, but it seems no one cares :smiley:

You can use wireshark to check if and how many Set-Cookie headers the response contains.

PHP sessions can use a URL parameter. Use that instead of cookies.