- Home /
PHP Sessions from WWW
Hi, I am trying to call a PHP which checks if a session is opened or not.
The PHP code is something like (let's call it get_session.php):
session_start();
isset($_SESSION['user_id']) or die("No open session! " . $_SESSION['user_id']);
And the Unity script is:
public IEnumerator GetData()
{
www = new WWW("http://localhost/get_session.php");
yield return www;
DataTransferred(www.text);
}
public void DataTransferred(string webdata)
{
Debug.Log(webdata);
}
Interestingly the same script while is working for some scenes, it is not working for others. :(
Any suggestions what to do?
thanks
please provide the UNITY script so we can see how you commmunicate. Do you use javascript or C# for building the WWW request etc.?
ok I've edited my question by adding some part of the unity script. Basically it is only about calling the PHP script. As I said it is not always working but I couldn't get the reason.
So, how does the session state get transferred from Unity to your server? I think PHP uses either cookies or URL rewriting to transfer the state. $$anonymous$$y guess is that you'll need to manually add this state to your requests.
PHP uses cookies. As far as I know Unity doesn't support them. I wonder if you took the session info and saved it in player prefs temporarily might work. Just be sure to delete it after the session expires.