Search Unity

POST variable not sending to website php file

Discussion in 'Editor & General Support' started by SamohtVII, May 4, 2020.

  1. SamohtVII

    SamohtVII

    Joined:
    Jun 30, 2014
    Posts:
    370
    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

    Code (CSharp):
    1. <b>Notice</b>:  Undefined variable: name in <b>/home/xxxxxxx/public_html/MyGame/Save.php</b> on line <b>38</b><br />
    2. <br />
    The code looks like this...

    Code (CSharp):
    1. WWWForm form = new WWWForm();
    2.         form.AddField("name", usersName);
    3.         form.AddField("score", highScore);
    4.         WWW www = new WWW("https://www.undivided.com/MyGame/Save.php", form);
    5.         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.

    Code (CSharp):
    1. if($_SERVER['REQUEST_METHOD'] == "POST"){
    2.         echo "We are POSTing<br />";
    3.     }
    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


    Code (CSharp):
    1. UploadAFile Log Null: We are posting<br />array(6) {
    2.   ["_GET"]=>
    3.   array(0) {
    4.   }
    5.   ["_POST"]=>
    6.   array(0) {
    7.   }
    8.   ["_COOKIE"]=>
    9.   array(0) {
    10.   }
    11.   ["_FILES"]=>
    12.   array(0) {
    13.   }
    14.   ["_SERVER"]=>
    15.   array(50) {
    16.     ["LSPHP_ENABLE_USER_INI"]=>
    17.     string(2) "on"
    18.     ["PATH"]=>
    19.     string(28) "/usr/local/bin:/bin:/bin"
    20.     ["TEMP"]=>
    21.     string(4) "/tmp"
    22.     ["TMP"]=>
    23.     string(4) "/tmp"
    24.     ["TMPDIR"]=>
    25.     string(4) "/tmp"
    26.     ["PWD"]=>
    27.     string(1) "/"
    28.     ["HTTP_ACCEPT"]=>
    29.     string(3) "*/*"
    30.     ["HTTP_ACCEPT_ENCODING"]=>
    31.     string(8) "identity"
    32.     ["CONTENT_TYPE"]=>
    33.     string(33) "application/x-www-form-urlencoded"
    34.     ["CONTENT_LENGTH"]=>
    35.     string(1) "0"
    36.     ["HTTP_HOST"]=>
    37.     string(15) "undivided.com"
    38.     ["HTTP_USER_AGENT"]=>
    39.     string(65) "UnityPlayer/2018.2.15f1 (UnityWebRequest/1.0, libcurl/7.52.0-DEV)"
    40.     ["HTTP_X_UNITY_VERSION"]=>
    41.     string(11) "2018.2.15f1"
    42.     ["HTTP_X_HTTPS"]=>
    43.     string(1) "1"
    44.     ["REDIRECT_UNIQUE_ID"]=>
    45.     string(27) "Xq9g99BbsdgfdsdfsdfgFAAABVY"
    46.     ["REDIRECT_SCRIPT_URL"]=>
    47.     string(34) "/MyGame/Save.html"
    48.     ["REDIRECT_SCRIPT_URI"]=>
    49.     string(57) "https://undivided.com/MyGame/Save.html"
    50.     ["REDIRECT_SERVER_ADMIN"]=>
    51.     string(20) "security@mywebsite.com.au"
    52.     ["REDIRECT_ps"]=>
    53.     string(5) "https"
    54.     ["REDIRECT_HTTPS"]=>
    55.     string(2) "on"
    56.     ["REDIRECT_SSL_TLS_SNI"]=>
    57.     string(15) "undivided.com"
    58.     ["REDIRECT_STATUS"]=>
    59.     string(3) "200"
    60.     ["UNIQUE_ID"]=>
    61.     string(27) "Xq9g99BbmhfghfgsdfgdsZkTEFAAABVY"
    62.     ["SCRIPT_URL"]=>
    63.     string(34) "/MyGame/Save.html"
    64.     ["SCRIPT_URI"]=>
    65.     string(57) "https://undivided.com/MyGame/Save.html"
    66.     ["SERVER_ADMIN"]=>
    67.     string(25) "webmaster@undivided.com"
    68.     ["ps"]=>
    69.     string(5) "https"
    70.     ["HTTPS"]=>
    71.     string(2) "on"
    72.     ["SSL_TLS_SNI"]=>
    73.     string(15) "undivided.com"
    74.     ["SERVER_SIGNATURE"]=>
    75.     string(0) ""
    76.     ["SERVER_SOFTWARE"]=>
    77.     string(6) "Apache"
    78.     ["SERVER_NAME"]=>
    79.     string(15) "undivided.com"
    80.     ["SERVER_ADDR"]=>
    81.     string(14) "43.234.654.123"
    82.     ["SERVER_PORT"]=>
    83.     string(3) "443"
    84.     ["REMOTE_ADDR"]=>
    85.     string(13) "12.123.12.123"
    86.     ["DOCUMENT_ROOT"]=>
    87.     string(30) "/home/fdgdsfasdf/public_html"
    88.     ["REQUEST_SCHEME"]=>
    89.     string(5) "https"
    90.     ["CONTEXT_PREFIX"]=>
    91.     string(0) ""
    92.     ["CONTEXT_DOCUMENT_ROOT"]=>
    93.     string(30) "/home/fsddasfdsda/public_html"
    94.     ["SCRIPT_FILENAME"]=>
    95.     string(63) "/home/fdsfdsfdsdfs/public_html/MyGame/Save.php"
    96.     ["REMOTE_PORT"]=>
    97.     string(5) "58931"
    98.     ["REDIRECT_URL"]=>
    99.     string(34) "/MyGame/Save.html"
    100.     ["SERVER_PROTOCOL"]=>
    101.     string(8) "HTTP/1.1"
    102.     ["REQUEST_METHOD"]=>
    103.     string(4) "POST"
    104.     ["QUERY_STRING"]=>
    105.     string(0) ""
    106.     ["REQUEST_URI"]=>
    107.     string(34) "/MyGame/Save.html"
    108.     ["SCRIPT_NAME"]=>
    109.     string(33) "/MyGame/Save.php"
    110.     ["PHP_SELF"]=>
    111.     string(33) "/MyGame/Save.php"
    112.     ["REQUEST_TIME_FLOAT"]=>
    113.     float(1588551927.163)
    114.     ["REQUEST_TIME"]=>
    115.     int(1588551927)
    116.   }
    117.   ["GLOBALS"]=>
    118.   array(6) {
    119.     ["_GET"]=>
    120.     array(0) {
    121.     }
    122.     ["_POST"]=>
    123.     array(0) {
    124.     }
    125.     ["_COOKIE"]=>
    126.     array(0) {
    127.     }
    128.     ["_FILES"]=>
    129.     array(0) {
    130.     }
    131.     ["_SERVER"]=>
    132.     array(50) {
    133.       ["LSPHP_ENABLE_USER_INI"]=>
    134.       string(2) "on"
    135.       ["PATH"]=>
    136.       string(28) "/usr/local/bin:/bin:/bin"
    137.       ["TEMP"]=>
    138.       string(4) "/tmp"
    139.       ["TMP"]=>
    140.       string(4) "/tmp"
    141.       ["TMPDIR"]=>
    142.       string(4) "/tmp"
    143.       ["PWD"]=>
    144.       string(1) "/"
    145.       ["HTTP_ACCEPT"]=>
    146.       string(3) "*/*"
    147.       ["HTTP_ACCEPT_ENCODING"]=>
    148.       string(8) "identity"
    149.       ["CONTENT_TYPE"]=>
    150.       string(33) "application/x-www-form-urlencoded"
    151.       ["CONTENT_LENGTH"]=>
    152.       string(1) "0"
    153.       ["HTTP_HOST"]=>
    154.       string(15) "undivided.com"
    155.       ["HTTP_USER_AGENT"]=>
    156.       string(65) "UnityPlayer/2018.2.15f1 (UnityWebRequest/1.0, libcurl/7.52.0-DEV)"
    157.       ["HTTP_X_UNITY_VERSION"]=>
    158.       string(11) "2018.2.15f1"
    159.       ["HTTP_X_HTTPS"]=>
    160.       string(1) "1"
    161.       ["REDIRECT_UNIQUE_ID"]=>
    162.       string(27) "Xq9g9etrrettgfdgfvvvdskTEFAAABVY"
    163.       ["REDIRECT_SCRIPT_URL"]=>
    164.       string(34) "/MyGame/Save.html"
    165.       ["REDIRECT_SCRIPT_URI"]=>
    166.       string(57) "https://undivided.com/MyGame/Save.html"
    167.       ["REDIRECT_SERVER_ADMIN"]=>
    168.       string(20) "security@mywebsite.com.au"
    169.       ["REDIRECT_ps"]=>
    170.       string(5) "https"
    171.       ["REDIRECT_HTTPS"]=>
    172.       string(2) "on"
    173.       ["REDIRECT_SSL_TLS_SNI"]=>
    174.       string(15) "undivided.com"
    175.       ["REDIRECT_STATUS"]=>
    176.       string(3) "200"
    177.       ["UNIQUE_ID"]=>
    178.       string(27) "Xq9g99BbgfdfhdhgghffdkTEFAAABVY"
    179.       ["SCRIPT_URL"]=>
    180.       string(34) "/MyGame/Save.html"
    181.       ["SCRIPT_URI"]=>
    182.       string(57) "https://undivided.com/MyGame/Save.html"
    183.       ["SERVER_ADMIN"]=>
    184.       string(25) "webmaster@undivided.com"
    185.       ["ps"]=>
    186.       string(5) "https"
    187.       ["HTTPS"]=>
    188.       string(2) "on"
    189.       ["SSL_TLS_SNI"]=>
    190.       string(15) "undivided.com"
    191.       ["SERVER_SIGNATURE"]=>
    192.       string(0) ""
    193.       ["SERVER_SOFTWARE"]=>
    194.       string(6) "Apache"
    195.       ["SERVER_NAME"]=>
    196.       string(15) "undivided.com"
    197.       ["SERVER_ADDR"]=>
    198.       string(14) "12.123.123.123"
    199.       ["SERVER_PORT"]=>
    200.       string(3) "443"
    201.       ["REMOTE_ADDR"]=>
    202.       string(13) "12.123.12.123"
    203.       ["DOCUMENT_ROOT"]=>
    204.       string(30) "/home/fdsdffdgsdf/public_html"
    205.       ["REQUEST_SCHEME"]=>
    206.       string(5) "https"
    207.       ["CONTEXT_PREFIX"]=>
    208.       string(0) ""
    209.       ["CONTEXT_DOCUMENT_ROOT"]=>
    210.       string(30) "/home/vddgfdsfdsdfs/public_html"
    211.       ["SCRIPT_FILENAME"]=>
    212.       string(63) "/home/hgffdggffgd/public_html/MyGame/Save.php"
    213.       ["REMOTE_PORT"]=>
    214.       string(5) "58931"
    215.       ["REDIRECT_URL"]=>
    216.       string(34) "/MyGame/Save.html"
    217.       ["SERVER_PROTOCOL"]=>
    218.       string(8) "HTTP/1.1"
    219.       ["REQUEST_METHOD"]=>
    220.       string(4) "POST"
    221.       ["QUERY_STRING"]=>
    222.       string(0) ""
    223.       ["REQUEST_URI"]=>
    224.       string(34) "/MyGame/Save.html"
    225.       ["SCRIPT_NAME"]=>
    226.       string(33) "/MyGame/Save.php"
    227.       ["PHP_SELF"]=>
    228.       string(33) "/MyGame/Save.php"
    229.       ["REQUEST_TIME_FLOAT"]=>
    230.       float(1588551927.163)
    231.       ["REQUEST_TIME"]=>
    232.       int(1588551927)
    233.     }
    234.     ["GLOBALS"]=>
    235.     *RECURSION*
    236.   }
    237. }
    238. N not setS not set<br />
    239. <b>Notice</b>:  Undefined variable: name in <b>/home/tidjbg2jr8pe/public_html/DownhillSlalom/SaveScorePOST.php</b> on line <b>38</b><br />
    240. <br />
    241. <b>Notice</b>:  Undefined variable: score in <b>/home/tidjbg2jr8pe/public_html/DownhillSlalom/SaveScorePOST.php</b> on line <b>39</b><br />
    242. <br />
    243. failarray(2) {
    244.   ["User"]=>
    245.   NULL
    246.   ["Score"]=>
    247.   NULL
    248. }
    249.  
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,914
    This doesn't really seem like a Unity issue at all. It seems like a bug in your PHP code, particularly in the file "SaveScorePOST.php" or "Save.php".
     
  3. SamohtVII

    SamohtVII

    Joined:
    Jun 30, 2014
    Posts:
    370
    Something is happening between sending the data from unity and receiving it on my website as there is no post data being received in the variables I print out. If I change the word POST to GET and update my unity code it works somehow.

    Aside from it possibly being on my server side do you have any debug methods I can try? I'm at my wits end trying to find this issue as it came completely out of the blue.

    EDIT: I can actually confirm an issue with Unity. If I use this site https://reqbin.com/ and put my variables in it will save correctly. So the POST data works when sending from anywhere but Unity :S

    Thanks
     
    Last edited: May 4, 2020
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,914
    One fishy thing I see is your are calling your form parameters "name" and "score" in Unity, but at the bottom of your error log I see:
    Code (CSharp):
    1. failarray(2) {
    2.   ["User"]=>
    3.   NULL
    4.   ["Score"]=>
    5.   NULL
    6. }
    Are your parameters supposed to be called "User" and "Score" instead?
     
  5. SamohtVII

    SamohtVII

    Joined:
    Jun 30, 2014
    Posts:
    370
    Sorry that's just me being a sloppy coder...

    Code (CSharp):
    1. if(isset($_POST["name"])) {
    2.         $name = $_POST["name"];
    3.     } else {
    4.         echo "N not set";
    5.     }
    6.  
    7.     if(isset($_POST["score"])) {
    8.         $score = $_POST["score"];
    9.     } else {
    10.         echo "S not set";
    11.     }
    12.  
    13.     $insert_data = array(
    14.         'User' => $name,
    15.         'Score' => $score
    16.     );
     
  6. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,914
    Silly question - in your Unity code what gets printed out if you do this before your WWW stuff:
    Code (CSharp):
    1. Debug.Log($"name: {usersName}, score: {highScore}");
     
  7. SamohtVII

    SamohtVII

    Joined:
    Jun 30, 2014
    Posts:
    370
    100% confirmed it is sending the correct variables. Usually like Tester123, and the score ~123456
     
  8. SamohtVII

    SamohtVII

    Joined:
    Jun 30, 2014
    Posts:
    370
  9. saifshk17

    saifshk17

    Joined:
    Dec 4, 2016
    Posts:
    488
    I am facing the same issue. Any solutions for this?
     
  10. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,752