- Home /
WWW execution (working in browser)
Hi again,
I am facing a very weird situation right now. I have a script which basically collects some data and tries to upload it to my mysql database. The process is verified by a md5 hash comparison.
So this is what happens: When I call my script via runtime it get's executed up to a very certain point and stops there for some reason I don't know yet (and I really hope that you can help me out here^^).
So this is the scenario:
Client side
var uploadScore = UploadScoreUrl + "name=" + WWW.EscapeURL(username) + "&score=" + &hash=" + hash;
Server Side
$real_hash = md5($name . $score . $secretKey);
if($real_hash == $hash) {$query = "insert into game_data values (NULL, '$name', '$score');";
´$result = mysql_query($query) or die('Query failed: ' . mysql_error());
So the weird thing is that if I print out the upload url that is generated on the client side (i.e. uploadScore) and execute it via the address bar in firefox the entry get's added to the database successfully. However this is not the case when I play the game. So by this I know that the Url is correct and indeed working! So what's next is to find the reason why the url is not submitted or executed during runtime.
I am using this code on client-side to submit the url:
score_post = WWW(uploadScore);
yield score_post; // Wait until the download is done
if(score_post.error) {
print("There was an error posting the score: " + score_post.error);
}
print (score_post.text);
Now this is what the last print tells me after the script has been called:
Connect to databse - Success! Get Score Information - Success! Hash is Fine! 208b74bc907059b208865033cb5c824d
However if I print the url out and execute it in the browser then the hash is different but the entry get's submitted successfully. (Hash in browser: 19d837242ac8eb9ac7daea90f7a53173)
So yes I believe that the script stops execution right before the hash comparison as the client says: Connect to databse - Success! Get Score Information - Success! Hash is Fine! 208b74bc907059b208865033cb5c824d
and the server says:
Connect to databse - Success! Get Score Information - Success! Hash is Fine! 19d837242ac8eb9ac7daea90f7a53173 19d837242ac8eb9ac7daea90f7a53173 Data Submitted successfull!
For your reference here's the code that's running on the server and obviously called by the client:
// This is the code that follows after the Hash is Fine! statement which is also to be found in the output log and therfore a proof that the script on the server is executed up to this point.
$real_hash = md5($name . $score . $secretKey);
echo " Hash is Fine! ";
echo $real_hash; //Generated by Server
echo " "; // Divider space for better representation
echo $hash; // Generated by Client
if($real_hash == $hash) {
// Send variables for the MySQL database class.
$query = "insert into game_data values (NULL, '$name', '$score');";
echo "Preparing Data.";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
echo " Data Submitted successfull!";
}
Again, the question is, why does the client generated url work in a browser like firefox, opera and chrome but not ingame?
I am also facing the same problem. I tried restarting the server. It worked once, but now again the same problem. Please post if you find an answer.
It seems the hash that is sent by the client contains illegal characters. The php script will just die silently in such a case. I'm a php novice. I tried some things in php and this was the first thing i absolutely hate about it. It makes debugging nearly impossible. Usually i just print / Debug.Log / whatever when i'm new to a system. I can do some tests how the system behaves. But php just quits execution when the data you echo / print contains illegal characters. I'm not sure what those characters are, but it could be a " or '.
Answer by JDB-Artist · Aug 16, 2012 at 08:16 PM
Thanks for your comments, I did not find the wrong character within the client script nor within the server script but as this script doesn't transfer valuable data I decided to drop the hash check on server side and now it stores the info correctly within the database.
I will post here if I find the char that mixes things up. THX for your help!
Answer by irfanbashasheik · Aug 16, 2012 at 09:11 PM
Hi,
I am also trying to fix similar problem. So far what i have noticed is the url string which i am building is missing some format.
I got it fixed. Just replace the spaces that you have in your url with %20.
Your answer
![](https://koobas.hobune.stream/wayback/20220613075750im_/https://answers.unity.com/themes/thub/images/avi.jpg)