Weishaupt, thanks and sorry for being a pain with all my questions :)
How would I do this serverside? I have a server which im currently hosting high scores on, So will it be similar?
Here is the PHP for posting..
<?php
// read variables from POST data.
$username = $HTTP_GET_VARS[name]; <-- DEFINE THE USER??
$score = $HTTP_GET_VARS[score]; // <-- MODIFY THIS TO SEND THE REPLAY??
// verify the username is set and not empty
if (!isset($username) || $username == "") {
echo "failure";
exit;
}
// verify the score is set and a number
if (!isset($score) || !is_numeric($score)) {
echo "failure";
exit;
}
// format the username and score as a comma delimited row
$entry = $username . "," . $score . "\n";
// append entry to the score file
if (!file_put_contents("scores.csv", $entry, FILE_APPEND)) {
echo "failure"; // failed to write to file
exit;
}
echo "success";
?>
Then Return the data
<?php
/** Return a list of top scores. */
// read variables from GET data
$num_scores = $HTTP_GET_VARS[num_scores];
// read each line in scores.csv as a string into an array
$scores = file("scores.csv");
// define a comparator to sort items by score
function compare($s1, $s2) {
// split the strings by their delimiter
$a1 = explode(",", $s1);
$a2 = explode(",", $s2);
// compare the scores
return $a2[1] - $a1[1];
}
// sort the array of scores
usort($scores, "compare");
// output the requested number of top scores
for ($i = 0; $i < $num_scores && $i < count($scores); $i++) {
echo $scores[$i];
}
?>
Can i send:
- int(tokenat(state,0,","))
- int(tokenat(state,1,","))
- int(tokenat(state,2,","))
instead of score? the retrieve it?