GingerBatMan:
Try the following PHPs:
<?php
// read variables from POST data.
$username = $HTTP_GET_VARS[name]; <-- DEFINE THE USER??
$log = $HTTP_GET_VARS[log]; // <-- MODIFY THIS TO SEND THE REPLAY??
// verify the username is set and not empty
if (!isset($username) || $username == "") {
echo "failure";
exit;
}
// verify the log is set and a number
if (!isset($log) || $log == "") {
echo "failure";
exit;
}
// format the username and log as a comma delimited row
$entry = $username . "#" . $log . "\n";
// append entry to the log file
if (!file_put_contents("logs.csv", $entry, FILE_APPEND)) {
echo "failure"; // failed to write to file
exit;
}
echo "success";
?>
...and...
<?php
/** Return a list of top logs. */
// read variables from GET data
$num_logs = $HTTP_GET_VARS[num_logs];
// read each line in logs.csv as a string into an array
$logs = file("logs.csv");
// define a comparator to sort items by log
function compare($s1, $s2) {
// split the strings by their delimiter
$a1 = explode("#", $s1);
$a2 = explode("#", $s2);
// compare the logs
return $a2[1] - $a1[1];
}
// sort the array of logs
usort($logs, "compare");
// output the requested number of top logs
for ($i = 0; $i < $num_logs && $i < count($logs); $i++) {
echo $logs[$i];
}
?>