Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Unity support PHP Sessions?

Does anyone know if Unity supports PHP sessions?

For example, let's say that a user signs into their account in Unity and submits the login information through WWW stream. Once logged in, I assign a session variable in my php script: $_SESSION['name]=name.

My question is, when the user comes to submit another request through Unity will the client still be able to access the session variable?

like image 300
Omar Dajani Avatar asked Apr 15 '26 11:04

Omar Dajani


1 Answers

Session data are data from a database connected to an id, which is used in the communication between client and server. Usually a cookie.

I can't say for certain, but I very much believe that the WWW class will ignore/forget cookies.

  1. Unity sends a request (with only the data you define) to PHP
  2. PHP sets a cookie corresponding to that session & responds to the request
  3. Unity gets the response with headers (and cookies in the headers)
  4. Repeat

PLEASE NOTE: I have not tested this, it is theoretical, but educated, guesses.


Suggested solution

You can set headers in your request that you build in Unity. If you save the headers from the response and add those to the request each time, you should be able to emulate the behaviour you're seeking. So basically:

  1. Unity sends a request (with headers = previousResponseHeaders) to PHP
  2. PHP reads the headers and connect your cookie to previous session & responds to the request
  3. Unity gets the response with headers (and cookies in the headers)
  4. Repeat

You set headers by doing something like this:

var headers = new Dictionary<string,string>();
headers.Add("Cookie", "key=value; semicolon=separated");
WWW www = new WWW("https://example.com", null, headers);
like image 82
Fredrik Schön Avatar answered Apr 18 '26 01:04

Fredrik Schön