Unity WebGL build and PHP Post communication
Hello, I am working on Unity Web-game and has a problem only in WebGL-build version uploaded to my server. On SendData Method I'm getting empty string as result.But in editor all ok.
My PHP looks like this:
<?php
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Allow-Headers: Accept, X-Access-Token, X-Application-Name, X-Request-Sent-Time");
$score = $_POST["Score"];
$filePath = "dataValue.txt";
$content="0";
if(filesize($filePath) >0)
{
$handler1 = fopen($filePath,'r');
$content = fread($handler1,filesize($filePath));
fclose($handler1);
}
if((int)$score<(int)$content)
{
$handler2 = fopen($filePath,'w+');
fwrite($handler2,$score);
fclose($handler2);
}
else {
}
?>
And C# Method:
public IEnumerator SendData(string data)
{
sendCoroutine = true;
// if(data==String.Empty)
// data = textField.text;
WWWForm form = new WWWForm();
form.AddField("Score",data);
WWW w =new WWW(url+"data.php",form);
yield return w;
if (w.error != null)
{
Debug.Log("Not Response");
}
else
{
Debug.Log("Response text: "+w.text);
//text.text = w.text.ToString();
}
w.Dispose();
sendCoroutine = false;
}
First Try Was No Using Headers, but and with them I dont get desired result... What a problem may be here? Thanks you for answers! I really need it!
Comment