Advertisement
Cherro

[PHP] Zgadnij wylosowaną liczbe

Mar 10th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.39 KB | None | 0 0
  1.  
  2. <!DOCTYPE html>
  3. <html lang="pl">
  4. <head>
  5.     <meta charset="UTF-8">
  6.     <title>Document</title>
  7. </head>
  8. <body>
  9.    <?php
  10. session_start();
  11.  
  12.     if(!isset($_SESSION['liczba']) || empty($_SESSION['liczba']))
  13.     {
  14.         $_SESSION['liczba'] = rand(1,5);
  15.         $_SESSION['ile'] = 1;
  16.     }
  17.  
  18.  
  19.  
  20.  
  21.  
  22. ?>
  23.   <form action="" method="post">
  24.      
  25.        Podaj liczbe o której myśle (od 1 do 5): <input type="number" name="liczba" min=1 max=5 > <br>
  26.    <input type="submit" name="subbutton" value="Wyślij">
  27.      
  28.   </form>
  29.  
  30.   <?php
  31.    
  32.     if(!empty($_POST['subbutton']))
  33.     {
  34.         if($_POST['liczba']>$_SESSION['liczba'])
  35.         {
  36.             echo "Za dużo! Spróbuj jeszcze raz! <br> Strona odświeży się za 3 sekundy...";
  37.             $_SESSION['ile']++;
  38.             header("Refresh: 3");
  39.             exit();
  40.         }
  41.         else if ($_POST['liczba']<$_SESSION['liczba'])
  42.         {
  43.             echo "Za mało! Spróbuj jeszcze raz! <br> Strona odświeży się za 3 sekundy...";
  44.             $_SESSION['ile']++;
  45.             header("Refresh: 3");
  46.             exit();
  47.         }
  48.         else
  49.         {
  50.             echo "Udało Ci się za ".$_SESSION['ile']." razem! Gratulacje!<br> Strona odświeży się za 3 sekundy...";
  51.             session_destroy();
  52.             header("Refresh: 3");
  53.             exit();
  54.         }
  55.     }
  56.    
  57.    
  58. ?>
  59.  
  60.    
  61. </body>
  62. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement