0
\$\begingroup\$

So I am attempting to keep track of some user data in my game that I am creating in Unity 3d. I am using Unity's WWW class to do this. I am following this tutorial: http://wiki.unity3d.com/index.php?title=Server_Side_Highscores

I am not sure why but I keep getting a 404 error even though the file is on the server. I am using godaddy to host my website and I have the php script that I am trying to access in there so that it can use it to query the database. I am using "http://www.mysite/myscript.php?" followed by the values that I want to push to the database, as the tutorial shows to do.

No matter what I do I end up with a 404 and it doesn't make any sense as I know that it is there in the path I am attempting to connect to. If I type out the path to the php file in a browser it will take me to a page that gives an error about the hash not existing (since I am not passing one unless it is in my game) so I know that the file is there.

3/18/16

Here is my php script to add the values to the database.

<?php
    $server = "MyServersIP";
    $user = "MyUser";
    $pass = "MyPassword";
    $db = "MyDB";

    $conn = mysql_connect($server, $user, $pass);

    mysql_select_db($db);

    $Username = mysql_real_escape_string($_GET['Username'], $db);
    $Fuel = mysql_real_escape_string($_GET['Fuel'], $db);
    $IAPCar1 = mysql_real_escape_string($_GET['IAPCar1'], $db);
    $IAPCar2 = mysql_real_escape_string($_GET['IAPCar2'], $db);
    $Score = mysql_real_escape_string($_GET['Score'], $db);
    $Level = mysql_real_escape_string($_GET['Level'], $db);
    $Wins = mysql_real_escape_string($_GET['Wins'], $db);
    $Losses = mysql_real_escape_string($_GET['Losses'], $db);
    $Ads = mysql_real_escape_string($_GET['Ads'], $db);
    $LicensePlate = mysql_real_escape_string($_GET['LicensePlate'], $db);
    $hash = $_GET['hash'];

    $secretKey = "mySecretKey";

    $real_hash = md5($Username . $Fuel . $IAPCar1 . $IAPCar2 . $Score .     $Level . $Wins . $Losses .
    $Ads . $LicensePlate . $hash);
    if ($real_hash == $hash)
    {
        $query = "INSERT INTO Player values (NULL, '$Username', '$Fuel', '$IAPCar1', '$IAPCar2',
        '$Score', '$Level', '$Wins', '$Losses', '$Ads', '$LicensePlate');";
        $result = mysql_query($query);
    }

    mysql_close($conn);
?>

Here is the code I use to call the php script:

public string setValues = "http://www.mysite.com/Set_Values.php?";
private string secretKey = "SecretKeyFromThePhpScript";
public void SetValues(string username, int fuel, bool iapCar1, bool iapCar2, int score,
    int level, int wins, int losses, bool ads, string licensePlate, bool firstTime)
{
    string hash = Md5Sum(string.Format("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}", username, fuel, iapCar1, iapCar2,
        score, level, wins, losses, ads, licensePlate, secretKey));
    string url = string.Format("{0}username={1}&fuel={2}&IAPCar1={3}&IAPCar2={4}&Score={5}&Level={6}" +
        "&Wins={7}&Losses={8}&Ads={9}&LicensePlate={10}&FirstTime={11}&hash={12}", setValues, username, fuel, iapCar1, iapCar2,
        score, level, wins, losses, ads, licensePlate, firstTime, secretKey);

    WWW www = new WWW(url);
}
\$\endgroup\$
  • \$\begingroup\$ Is your file really hosted at www.mysite? \$\endgroup\$ – Almo Mar 18 '16 at 2:04
  • \$\begingroup\$ @Almo Yes I put the php file in the fileague manager and I can't type the path into a browser and get an error since I don't add the hash for the file. \$\endgroup\$ – saboehnke Mar 18 '16 at 5:03
  • \$\begingroup\$ I don't think you understand my question. Are you putting literally "mysite"? What's "fileague"? What do you mean "hash for the file"? This is only getting more confusing. \$\endgroup\$ – Almo Mar 18 '16 at 13:04
  • \$\begingroup\$ @Almo No I am putting the actual address to the site. And that should have said file manager but my phone "corrected" me lol. The hash is the secret key used to confirm the calls are being made from the game. You,can see that in the link to the tutorial I am using. \$\endgroup\$ – saboehnke Mar 18 '16 at 14:30
  • \$\begingroup\$ OK, at this point you should include some of your code (only the relevant bits) in the question itself. External links have a habit of dying. \$\endgroup\$ – Almo Mar 18 '16 at 14:32
0
\$\begingroup\$

The solution to my issue turned out to be that I had a typo in my url that I used. Also I needed to change $db to $conn where I am getting the values and assigning them to variables.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.