- Home /
POST variable not sending to website php file
So I am having a huge issue where my php files don't recieve my form fields from Unity all of a sudden. I get
<b>Notice</b>: Undefined variable: name in <b>/home/xxxxxxx/public_html/MyGame/Save.php</b> on line <b>38</b><br> <br>
The code looks like this...
WWWForm form = new WWWForm(); form.AddField("name", usersName); form.AddField("score", highScore); WWW www = new WWW("https://www.undivided.com/MyGame/Save.php", form); yield return www;
This worked 2 weeks ago but I think something changed on my web server to effect this. I need help debugging this as I can't pin point what went wrong. Can anyone suggest some debugging methods.
I have found this.
if($_SERVER['REQUEST_METHOD'] == "POST"){ echo "We are POSTing<br />"; }
which prints out.
I also printed out my $GLOBALS and it returned this... Sorry for the wall of text but I feel it might help...As you can see there are no post varibales.
Thanks
UploadAFile Log Null: We are posting<br>array(6) { ["_GET"]=> array(0) { } ["_POST"]=> array(0) { } ["_COOKIE"]=> array(0) { } ["_FILES"]=> array(0) { } ["_SERVER"]=> array(50) { ["LSPHP_ENABLE_USER_INI"]=> string(2) "on" ["PATH"]=> string(28) "/usr/local/bin:/bin:/bin" ["TEMP"]=> string(4) "/tmp" ["TMP"]=> string(4) "/tmp" ["TMPDIR"]=> string(4) "/tmp" ["PWD"]=> string(1) "/" ["HTTP_ACCEPT"]=> string(3) "*/*" ["HTTP_ACCEPT_ENCODING"]=> string(8) "identity" ["CONTENT_TYPE"]=> string(33) "application/x-www-form-urlencoded" ["CONTENT_LENGTH"]=> string(1) "0" ["HTTP_HOST"]=> string(15) "undivided.com" ["HTTP_USER_AGENT"]=> string(65) "UnityPlayer/2018.2.15f1 (UnityWebRequest/1.0, libcurl/7.52.0-DEV)" ["HTTP_X_UNITY_VERSION"]=> string(11) "2018.2.15f1" ["HTTP_X_HTTPS"]=> string(1) "1" ["REDIRECT_UNIQUE_ID"]=> string(27) "Xq9g99BbsdgfdsdfsdfgFAAABVY" ["REDIRECT_SCRIPT_URL"]=> string(34) "/MyGame/Save.html" ["REDIRECT_SCRIPT_URI"]=> string(57) "https://undivided.com/MyGame/Save.html" ["REDIRECT_SERVER_ADMIN"]=> string(20) "security@mywebsite.com.au" ["REDIRECT_ps"]=> string(5) "https" ["REDIRECT_HTTPS"]=> string(2) "on" ["REDIRECT_SSL_TLS_SNI"]=> string(15) "undivided.com" ["REDIRECT_STATUS"]=> string(3) "200" ["UNIQUE_ID"]=> string(27) "Xq9g99BbmhfghfgsdfgdsZkTEFAAABVY" ["SCRIPT_URL"]=> string(34) "/MyGame/Save.html" ["SCRIPT_URI"]=> string(57) "https://undivided.com/MyGame/Save.html" ["SERVER_ADMIN"]=> string(25) "webmaster@undivided.com" ["ps"]=> string(5) "https" ["HTTPS"]=> string(2) "on" ["SSL_TLS_SNI"]=> string(15) "undivided.com" ["SERVER_SIGNATURE"]=> string(0) "" ["SERVER_SOFTWARE"]=> string(6) "Apache" ["SERVER_NAME"]=> string(15) "undivided.com" ["SERVER_ADDR"]=> string(14) "43.234.654.123" ["SERVER_PORT"]=> string(3) "443" ["REMOTE_ADDR"]=> string(13) "12.123.12.123" ["DOCUMENT_ROOT"]=> string(30) "/home/fdgdsfasdf/public_html" ["REQUEST_SCHEME"]=> string(5) "https" ["CONTEXT_PREFIX"]=> string(0) "" ["CONTEXT_DOCUMENT_ROOT"]=> string(30) "/home/fsddasfdsda/public_html" ["SCRIPT_FILENAME"]=> string(63) "/home/fdsfdsfdsdfs/public_html/MyGame/Save.php" ["REMOTE_PORT"]=> string(5) "58931" ["REDIRECT_URL"]=> string(34) "/MyGame/Save.html" ["SERVER_PROTOCOL"]=> string(8) "HTTP/1.1" ["REQUEST_METHOD"]=> string(4) "POST" ["QUERY_STRING"]=> string(0) "" ["REQUEST_URI"]=> string(34) "/MyGame/Save.html" ["SCRIPT_NAME"]=> string(33) "/MyGame/Save.php" ["PHP_SELF"]=> string(33) "/MyGame/Save.php" ["REQUEST_TIME_FLOAT"]=> float(1588551927.163) ["REQUEST_TIME"]=> int(1588551927) } ["GLOBALS"]=> array(6) { ["_GET"]=> array(0) { } ["_POST"]=> array(0) { } ["_COOKIE"]=> array(0) { } ["_FILES"]=> array(0) { } ["_SERVER"]=> array(50) { ["LSPHP_ENABLE_USER_INI"]=> string(2) "on" ["PATH"]=> string(28) "/usr/local/bin:/bin:/bin" ["TEMP"]=> string(4) "/tmp" ["TMP"]=> string(4) "/tmp" ["TMPDIR"]=> string(4) "/tmp" ["PWD"]=> string(1) "/" ["HTTP_ACCEPT"]=> string(3) "*/*" ["HTTP_ACCEPT_ENCODING"]=> string(8) "identity" ["CONTENT_TYPE"]=> string(33) "application/x-www-form-urlencoded" ["CONTENT_LENGTH"]=> string(1) "0" ["HTTP_HOST"]=> string(15) "undivided.com" ["HTTP_USER_AGENT"]=> string(65) "UnityPlayer/2018.2.15f1 (UnityWebRequest/1.0, libcurl/7.52.0-DEV)" ["HTTP_X_UNITY_VERSION"]=> string(11) "2018.2.15f1" ["HTTP_X_HTTPS"]=> string(1) "1" ["REDIRECT_UNIQUE_ID"]=> string(27) "Xq9g9etrrettgfdgfvvvdskTEFAAABVY" ["REDIRECT_SCRIPT_URL"]=> string(34) "/MyGame/Save.html" ["REDIRECT_SCRIPT_URI"]=> string(57) "https://undivided.com/MyGame/Save.html" ["REDIRECT_SERVER_ADMIN"]=> string(20) "security@mywebsite.com.au" ["REDIRECT_ps"]=> string(5) "https" ["REDIRECT_HTTPS"]=> string(2) "on" ["REDIRECT_SSL_TLS_SNI"]=> string(15) "undivided.com" ["REDIRECT_STATUS"]=> string(3) "200" ["UNIQUE_ID"]=> string(27) "Xq9g99BbgfdfhdhgghffdkTEFAAABVY" ["SCRIPT_URL"]=> string(34) "/MyGame/Save.html" ["SCRIPT_URI"]=> string(57) "https://undivided.com/MyGame/Save.html" ["SERVER_ADMIN"]=> string(25) "webmaster@undivided.com" ["ps"]=> string(5) "https" ["HTTPS"]=> string(2) "on" ["SSL_TLS_SNI"]=> string(15) "undivided.com" ["SERVER_SIGNATURE"]=> string(0) "" ["SERVER_SOFTWARE"]=> string(6) "Apache" ["SERVER_NAME"]=> string(15) "undivided.com" ["SERVER_ADDR"]=> string(14) "12.123.123.123" ["SERVER_PORT"]=> string(3) "443" ["REMOTE_ADDR"]=> string(13) "12.123.12.123" ["DOCUMENT_ROOT"]=> string(30) "/home/fdsdffdgsdf/public_html" ["REQUEST_SCHEME"]=> string(5) "https" ["CONTEXT_PREFIX"]=> string(0) "" ["CONTEXT_DOCUMENT_ROOT"]=> string(30) "/home/vddgfdsfdsdfs/public_html" ["SCRIPT_FILENAME"]=> string(63) "/home/hgffdggffgd/public_html/MyGame/Save.php" ["REMOTE_PORT"]=> string(5) "58931" ["REDIRECT_URL"]=> string(34) "/MyGame/Save.html" ["SERVER_PROTOCOL"]=> string(8) "HTTP/1.1" ["REQUEST_METHOD"]=> string(4) "POST" ["QUERY_STRING"]=> string(0) "" ["REQUEST_URI"]=> string(34) "/MyGame/Save.html" ["SCRIPT_NAME"]=> string(33) "/MyGame/Save.php" ["PHP_SELF"]=> string(33) "/MyGame/Save.php" ["REQUEST_TIME_FLOAT"]=> float(1588551927.163) ["REQUEST_TIME"]=> int(1588551927) } ["GLOBALS"]=> *RECURSION* } } N not setS not set<br> <b>Notice</b>: Undefined variable: name in <b>/home/tidjbg2jr8pe/public_html/DownhillSlalom/SaveScorePOST.php</b> on line <b>38</b><br> <br> <b>Notice</b>: Undefined variable: score in <b>/home/tidjbg2jr8pe/public_html/DownhillSlalom/SaveScorePOST.php</b> on line <b>39</b><br> <br> failarray(2) { ["User"]=> NULL ["Score"]=> NULL }
Answer by SamohtVII · May 04, 2020 at 01:41 AM
Sorry I did forget to mention I used https://reqbin.com/ to send POST data and it returns fine so it seems to be something with Unity or something that my website doesn't like about Unity. I hoping you can help me debug the Unity side of it. It's a standard LAMP website with fresh SSL certs. No custom config stuff as I'm not experienced in that. I would think the wierdest things are it accepts it when I change the code to GET and also accepts from everywhere but Unity and my builds. I am using the Editor but building for Android. Let me know if that helps at all. Thanks
Fuck, something happened when I updated my SSl i think. $$anonymous$$y fix was changing https://www.undivided.com/$$anonymous$$yGame/Save.php to https://undivided.com/$$anonymous$$yGame/Save.html Thanks for the help though.
Don't you have a wilecard certificate for your server? For example this is the certificate for unity.com. The important things are the list of SANs which for this certificate are
unity.com
*.unity.com
Unity answers however answers.unity.com
has a seperate certificate since its domain name resolves to a different server
Answer by Bunny83 · May 04, 2020 at 01:30 AM
Well, yes, I would also assume that's an issue on your server side. However we can't really help you here since we know absolutely nothing about your server. Do you host it yourself? Or is it a free hoster / paid hoster? Do you have direct access to the apache config / php config? You use https so the next question is, what certificate do you use? If you use a lets encrypt certificate, keep in mind that they expire after 3 month and have to be renewed.
Apart from all that what's your actual platform your testing your code on? Inside the editor? windows standalone? WebGL? Android? iOS? Can you temporarily switch to http if your server allows it? If you use http you can use Wireshark on windows to intercept and view the actual request. If you're building for WebGL you can use the developer tools of your browser (FireFox or chrome has them) to see the requests and all data that actually goes out.
You can try postman-echo.com and temporarily send your request to that site. It will return all the data the server has received in it's response as json.
Likewise there are other sites (like this one) which allows to make arbitrary post requests to a specified server. So you should be able to test both sides in isolation.
Your answer
Follow this Question
Related Questions
Best online servers for Web Browser Multiplayer? 2 Answers
Read second Line of WWWForm.data 1 Answer
Retrieve a value from a PHP file and print it on the Unity3D console. 1 Answer
unity + php get Authentication 0 Answers
Using https and SSL 1 Answer