• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by J3-Gaming · Nov 22, 2012 at 09:47 PM · wwwwwwformheaderscookies

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image J3-Gaming · Nov 23, 2012 at 02:10 AM 0
Share

That explains why I only get 1 Set-Cookie response. Thanks.

avatar image J3-Gaming · Nov 27, 2012 at 07:06 AM 0
Share

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?

avatar image
0

Answer by Graham-Dunnett · Nov 22, 2012 at 10:47 PM

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image J3-Gaming · Nov 23, 2012 at 12:04 AM 0
Share

How would that work if the website relies on cookies? I do not own the website and do not have access to edit it.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Posting raw XML data to web - no parameter name 2 Answers

How do I add a header and a file at the web request at the same time? 0 Answers

send json with https using post on android can't get response. 0 Answers

How can I get Hello World message from web service (WSDL/SOAP) using WWW class? 0 Answers

Disable execute/write permissions on PHP files while maintaining the ability to execute them from Unity? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges