ich habe hier einen php script der für eine Highscore ist und der mit der MySql Datenbank kommuniziert.
Dieser Script schreibt nur Dateien in die Datenbank, wenn die score vom einen Spieler anders ist.
Ich benötige das dieser script auch wenn die score gleich ist wie die in der Datenbank, das er diese Score einträgt.
Danke !
Code: Alles auswählen
// Get Configuation file
require("config.php");
// Connect to your server
$db=mysql_connect($host,$user,$pass) or die(mysql_error(mysql_error()));
@mysql_select_db($dbname) or die (mysql_error(mysql_error()));
///////////////////////////////////////////////////////
// Status Checker
///////////////////////////////////////////////////////
if ($_REQUEST["status"])
{
echo "online";
exit;
}
///////////////////////////////////////////////////////
// Upload new score
///////////////////////////////////////////////////////
// Test for the variables submitted by the player
// If they exist upload into the database
if ($_REQUEST["playername"] && $_REQUEST["gameid"] && $_REQUEST["score"])
{
// Strip out | marks submitted in the name or score
$playername_safe = str_replace("|","_",$_REQUEST["playername"]);
$playername_safe = mysql_real_escape_string($playername_safe);
$gameid_safe = mysql_real_escape_string($_REQUEST["gameid"]);
$score_safe = mysql_real_escape_string($_REQUEST["score"]);
$date = date('M d Y');
// Check the score sent is is numeric
// If the score is not numberic lets set it to zero
if(!is_numeric($score))
{
$score=0;
}
// this secret key needs to be the same as the secret key in your game.
$security_md5= md5($_REQUEST["gameid"].$_REQUEST["playername"].$_REQUEST["score"].$secret_key);
// Check for submitted MD5 different then server generated MD5
if ($security_md5 <>$_REQUEST["code"])
{
// Something is wrong -- MD5 security hash is different
// Could be someone trying to insert bogus score data
exit;
}
// Everything is cool -- Insert the data into the database
// No wait! we should update insted
// first check if there is a score with the same score and if it is update it, if not insert
$query1 ="select * from $tname where score = '$score_safe'";
$countresults = mysql_query($query1)or die(mysql_error(mysql_error()));
$countofdeletes = mysql_num_rows($countresults);
if (mysql_num_rows($countresults)>0)
{
$query = "UPDATE $tname SET playername='$playername_safe', scoredate='$date', md5='$security_md5' WHERE score = '$score_safe' AND gameid='$gameid_safe'";
$insert_the_data = mysql_query($query)or die(mysql_error());
}elseif(mysql_num_rows($countresults)==0){
$query = "insert into $tname(gameid,playername,score,scoredate,md5) values ('$gameid_safe','$playername_safe','$score_safe','$date','$security_md5')";
$insert_the_data = mysql_query($query)or die(mysql_error());
}
}
///////////////////////////////////////////////////////
// List high score
///////////////////////////////////////////////////////
// Return a list of high scores with "|" as the delimiter
if ($_REQUEST["gameid"])
{
$gameid_safe = mysql_real_escape_string($_REQUEST["gameid"]);
$query = "select * from $tname where gameid = '$gameid_safe' order by score desc limit 1";
$view_data = mysql_query($query)or die(mysql_error(mysql_error()));
while($row_data = mysql_fetch_array($view_data))
{
echo $row_data["playername"];
echo "|";
echo $row_data["score"];
echo "|";
echo $row_data["scoredate"];
echo "|";
}
// We limit the score database to hold only the 1 highest scores per game
// Delete the 11th lowest score for this game
// First check to see how many records we have for this game