Advertisement
kklevi

numbers

Oct 18th, 2022
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.69 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.  
  4. <head>
  5.     <meta charset="UTF-8">
  6.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8.     <title>Document</title>
  9. </head>
  10.  
  11. <body>
  12.     <?php
  13.     session_start();
  14.     if (!isset($_SESSION['number']) || (isset($_GET['number']) && $_GET['number'] == 'new')) {
  15.         $_SESSION['number'] = rand(0, 100);
  16.         $_SESSION['try'] = 0;
  17.         $_SESSION['tries'] = array();
  18.         $_SESSION['done'] = false;
  19.     }
  20.     echo 'a keresendő érték:' . $_SESSION['number'] . '<BR>';
  21.     if (isset($_POST['submit'])) {
  22.         $probak = $_SESSION['tries'];
  23.         $probak[] = $_POST['number'];
  24.         $_SESSION['tries'] = $probak;
  25.  
  26.         $_SESSION['try']++;
  27.         if ($_POST['number'] < $_SESSION['number']) {
  28.             echo 'a keresett szám nagyobb, mint ' . $_POST['number'] . '<BR>';
  29.         } else
  30.         if ($_POST['number'] > $_SESSION['number']) {
  31.             echo 'a keresett szám kisebb, mint ' . $_POST['number'] . '<BR>';
  32.         } else {
  33.             echo 'megtaláltad a keresett számot!' . $_SESSION['number'] . '<BR>';
  34.             $_SESSION['done'] = true;
  35.         }
  36.         echo 'A próbálkozások száma:' . $_SESSION['try'] . '<BR>';
  37.     }
  38.     foreach ($_SESSION['tries'] as $k => $v) {
  39.         echo ($k + 1) . ' --> ' . $v . '<BR>';
  40.     }
  41.  
  42.     echo '<BR><a href="games2.php?number=new">Új szám generálása</a>';
  43.  
  44.     if (!$_SESSION['done']) {
  45.         echo '
  46.         <FORM NAME="form1" method="POST" action="games2.php">
  47.         <INPUT type="text" name="number">
  48.         <INPUT type="submit" name="submit" value="Probal">
  49.         </FORM>
  50.     ';
  51.     }
  52.     ?>
  53. </body>
  54.  
  55. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement