This may or may not be of any use to you, its a simple high score table I wrote for one of my projects (it was quick and hack like so don't expect anything major, its pretty basic and lacks security ... badly), just upload to your server and send a HTTP request via a socket (Look at the GNet source code in the archives or use google if you don't know how to do this) to your server every time you want to check or update it.
<?
/* **************************************************************************
File: HighScore.php
Site: BinaryPhoenix.com
Description: Allows the user to preform several basic high-score actions
such as send and retrieving high score results.
************************************************************************** */
// Stores global variables describing how to process this request.
$Action = $_GET["action"];
$Game = $_GET["game"];
$Name = $_GET["name"];
$Score = $_GET["score"];
$HighScoreCount = $_GET["count"];
$DatabaseHost = "localhost";
$DatabaseName = "-=Your database name here=-";
$DatabaseUsername = "-=Your database username here=-";
$DatabasePassword = "-=Your database password here=-";
// Connect to the database.
if (!mysql_connect($DatabaseHost,$DatabaseUsername,$DatabasePassword)) die("Unable to connect to database");
if (!mysql_select_db($DatabaseName)) die("Unable to select database");
// Preform action.
switch($Action)
{
case "exists":
// Check values are valid.
if ($Game == "" || $Name == "") Die("Invalid data.");
// Check for value and return true or false if it exists.
$Result = mysql_query("SELECT * FROM Scores WHERE Game='" . $Game . "' AND Name='" . $Name . "'");
if (mysql_num_rows($Result) > 0)
echo("1");
else
echo("0");
break;
case "send":
// Check values are valid.
if ($Game == "" || $Name == "" || $Score == "") Die("Invalid data.");
// Add score to database.
mysql_query("INSERT INTO Scores VALUES ('','" . $Name . "','" . $Score . "','" . $Game . "')");
break;
case "retrieve":
// Check values are valid.
if ($Game == "" || $HighScoreCount == "") Die("Invalid data.");
// Retrieve value from database.
$Result = mysql_query("SELECT * FROM Scores WHERE Game='" . $Game . "' ORDER BY Score DESC LIMIT " . $HighScoreCount);
// Echo out the high scores.
for ($index = 0; $index < mysql_num_rows($Result); $index++)
{
$EntryData = mysql_fetch_assoc($Result);
echo( $EntryData["Name"] . "=" . $EntryData["Score"] . "\n");
}
break;
case "view":
// Check values are valid.
if ($Game == "") Die("Invalid data.");
// Retrieve value from database.
$Result = mysql_query("SELECT * FROM Scores WHERE Game='" . $Game . "' ORDER BY Score DESC");
// Echo out the high scores.
for ($index = 0; $index < mysql_numrows($Result); $index++)
{
$EntryData = mysql_fetch_assoc($Result);
echo( $EntryData["Name"] . "=" . $EntryData["Score"] . "<br/>");
}
break;
default:
Die("Invalid operation");
break;
}
// Close connection to database.
mysql_close();
?>
|