I created a web application that uses a php file on server to store and process value. In my web application I embedded Unity web player as means of visualisation.
When I run my program from server, and execute php file manually via browser, I can see that I am using same sessionid.
Although they are on the same session id, and I am able to get reply from server in my html element but Unity seems ignoring input from server. Could someone tell me what am I missing? Am I using the WWW correctly? I’m not getting any errors on my end. No errors in Chrome’s dev tool. No error in Unity.
In my unity I use:
function Listen() {
while(true) {
yield WaitForSeconds(0.15);
ListenForNewMessage();
}
}
function ListenForNewMessage() {
// if we have it, use it to retreive information
var url = "http://localhost/colourChanger.php";
var www : WWW = new WWW (url);
// wait for request to complete
yield www;
// and check for errors
if (www.error == null)
{
// request completed!
} else {
// something wrong!
Debug.Log("WWW Error: "+ www.error);
}
if(www.text == "Red" || www.text == "Green" ||
www.text == "Yellow" || www.text == "White") {
var component = sphere.GetComponent(ColourSwitcher);
component.SwitchColor(www.text);
message = "Received: " + www.text;
} else {
Debug.Log("No Input");
message = "No input. " + www.text; // will get the sessionid instead as per php code
}
}
My php contains:
<?php
session_start();
$sessionid = session_id();
echo $sessionid;
$ballColour = "White";
$_SESSION['ballColour'] = $ballColour;
//----Change ball colour----//
if (isset($_POST['ballColour'])) {
$_SESSION['ballColour'] = $_POST['ballColour'];
echo $_SESSION['ballColour'];
} else {
}
?>