Guest User

Untitled

a guest
Jun 24th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.87 KB | None | 0 0
  1. <?php
  2.  
  3.     /* Darts scorekeeper v1.0
  4.     Tue Feb 7 2012, KnickLighter */
  5.  
  6.     // Configuration
  7.     $ds_game = "501";
  8.  
  9.     session_start();
  10.  
  11.     if ($_GET['act'] == "start") {
  12.         $_SESSION['active'] = "yes";
  13.         $_SESSION['score'] = $ds_game;
  14.         $_SESSION['avg'] = "0";
  15.         $_SESSION['throws'] = "0";
  16.         $_SESSION['scored'] = array();
  17.     }
  18.  
  19.     function ds_restart () { header("Location: index.php?act=start"); }
  20.     function ds_error ($ds_err) {
  21.         echo "<h1>Error!</h1><p>".$ds_err."</p><p>Click <a href=\"index.php\">here</a> to go back!";
  22.         die();
  23.     }
  24.  
  25.     if ($_GET['act'] == "throw") {
  26.         if (isset($_GET['score'])) {
  27.             $ds_score = htmlspecialchars($_GET['score']);
  28.             if (!is_numeric($ds_score)) { ds_error("Score not numeric!"); }
  29.             if ($ds_score == $_SESSION['score'] - 1) { ds_error("Score too high!"); }
  30.             if ($ds_score > "180") { ds_error("Did you really score 180+?"); }
  31.             if ($ds_score == $_SESSION['score']) { ds_restart(); }
  32.             $_SESSION['score'] = $_SESSION['score'] - $ds_score;
  33.             array_push($_SESSION['scored'], $ds_score);
  34.             $_SESSION['throws'] = $_SESSION['throws'] + 1;
  35.             $_SESSION['avg'] = ($ds_game - $_SESSION['score']) / ($_SESSION['throws']);
  36.         }
  37.     }
  38. ?>
  39.  
  40. <html>
  41. <head>
  42. <title>Darts</title>
  43. </head>
  44. <body onload="document.score.score.focus();">
  45. <table width="100%">
  46. <tr>
  47. <td align="left"><a href="index.php?act=start">Start</a> |</td>
  48. <td align="right">Darts thrown: <? echo $_SESSION['throws'] * 3 ." (".round($_SESSION['avg'], 2)." avg.)"; ?></td>
  49. <tr>
  50. </table>
  51. <hr>
  52. <h1><? echo $_SESSION['score']; ?></h1>
  53. <hr>
  54. <form name="score" method="GET">
  55. <input type="hidden" name="act" value="throw">
  56. <input type="text" name="score" autocomplete="off">
  57. <input type="submit" value="Throw!">
  58. </form>
  59. <hr>
  60. <?php
  61.  
  62.     $ds_amount = count($_SESSION['scored']);
  63.  
  64.     for ($i = $ds_amount; $i >= 0; $i--) {
  65.         echo $_SESSION['scored'][$i] ."\n<br>";
  66.     }
  67.  
  68. ?>
  69. </body>
  70. </html>
Add Comment
Please, Sign In to add comment