- Home /
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;
ProcessHeaders(www.responseHeaders);
isLoggedIn = true;
ScanHTML(www.text);
}
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.
Answer by Bunny83 · Nov 23, 2012 at 12:31 AM
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 :D
edit
You can use wireshark to check if and how many Set-Cookie headers the response contains.
That explains why I only get 1 Set-Cookie response. Thanks.
error CS0246: The type or namespace name `async' could not be found. Are you missing a using directive or an assembly reference?
It appears we cannot use HttpClient async like we do for IEnumerator. Any other ideas or example code?
Answer by Graham-Dunnett · Nov 22, 2012 at 10:47 PM
PHP sessions can use a URL parameter. Use that instead of cookies.
How would that work if the website relies on cookies? I do not own the website and do not have access to edit it.