scores.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. $score = $_POST["score"];
  3. echo "<html>";
  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"];
  9. if($name == "")
  10. $name = "Anonymous";
  11. //if($grid != "10x10"){
  12. //Need a standard, so as to reject others?
  13. //}
  14. $file = fopen("score_data.xml", "a"); #It's XML. Happy?
  15. $ret = fwrite($file, "<record><score>". $score . "</score><name>"
  16. . $name . "</name><gridSize>" . $grid . "</gridSize><seconds>"
  17. . $time . "</seconds></record>\n");
  18. echo "Your score has been recorded. Thanks for playing!";
  19. if($ret == False)
  20. echo "<br/> There was an error though, so don't expect to see that score again.";
  21. }else{#Read high score list
  22. #Now uses XSLT to display. So just print the file. With XML cruft added.
  23. #Note that firefox at least won't apply the XSLT on a php file. So redirecting
  24. $file = fopen("scores.xml", "w");
  25. $ret = fwrite($file, '<?xml version="1.0" encoding="ISO-8859-1"?>' . "\n"
  26. . '<?xml-stylesheet type="text/xsl" href="score_style.xsl"?>' . "\n"
  27. . "<records>\n" . file_get_contents("score_data.xml") . "</records>\n");
  28. if($ret == False)
  29. echo "There was an internal error. Sorry.";
  30. else
  31. echo '<script type="text/javascript">window.location.replace("scores.xml")</script>';
  32. }
  33. echo "</body></html>";
  34. ?>