2 $score = $_POST["score"];
4 echo "<head><title>SameGame High Scores</title></head><body>";
5 if($score > 0){#Sending in a new high score
6 $name = $_POST["name"];
7 $grid = $_POST["gridSize"];
8 $time = $_POST["time"];
11 $file = fopen("score_data.xml", "a");
12 $ret = fwrite($file, "<record><score>". $score . "</score><name>"
13 . $name . "</name><gridSize>" . $grid . "</gridSize><seconds>"
14 . $time . "</seconds></record>\n");
15 echo "Your score has been recorded. Thanks for playing!";
17 echo "<br/> There was an error though, so don't expect to see that score again.";
18 }else{#Read high score list
19 #Now uses XSLT to display. So just print the file. With XML cruft added.
20 #Note that firefox at least won't apply the XSLT on a php file. So redirecting
21 $file = fopen("scores.xml", "w");
22 $ret = fwrite($file, '<?xml version="1.0" encoding="ISO-8859-1"?>' . "\n"
23 . '<?xml-stylesheet type="text/xsl" href="score_style.xsl"?>' . "\n"
24 . "<records>\n" . file_get_contents("score_data.xml") . "</records>\n");
26 echo "There was an internal error. Sorry.";
28 echo '<script type="text/javascript">window.location.replace("scores.xml")</script>';
30 echo "</body></html>";