Guest User

Untitled

a guest
Mar 29th, 2021
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.97 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <meta charset="utf-8"/>
  5. </head>
  6. <body>
  7. <form action="" method="POST">
  8.     <fieldset>
  9.         <legend>PESEL DECODER</legend>
  10.         <p>Pesel: <input name="pesel"></p>
  11.         <p><input name="sub1" type="submit" value="Prześlij"></p>
  12.     </fieldset>
  13. </form>
  14.  
  15. </body>
  16. </html>
  17.  
  18. <?php
  19.  
  20. if (isset($_POST['sub1'])) {
  21.  
  22.     if (isset($_POST['pesel'])) {
  23.  
  24.         if (is_numeric($_POST['pesel'])) {
  25.             $sum = 0;
  26.             $weights = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3];
  27.  
  28.             for ($i = 0; $i < $_POST['pesel'] - 1; $i++) {
  29.                 $sum += substr($_POST['pesel'], $i, $i + 1) * $weights[$i];
  30.                 echo "test<br>";
  31.             }
  32.             echo "test2";
  33.             $sum = $sum % 10;
  34.             if ($sum == 10)
  35.                 $sum = 0;
  36.             if ($sum == $_POST['pesel'][10])
  37.                 $iscorrect = true;
  38.             else
  39.                 $iscorrect = false;
  40.  
  41.             $year = substr($_POST['pesel'], 0, 2);
  42.             $month = substr($_POST['pesel'], 2, 4);
  43.             $day = substr($_POST['pesel'], 4, 6);
  44.             if ($month >= 80) {
  45.                 $year += 1800;
  46.                 $month -= 80;
  47.             } elseif ($month >= 60) {
  48.                 $year += 2200;
  49.                 $month -= 60;
  50.             } elseif ($month >= 40) {
  51.                 $year += 2100;
  52.                 $month -= 40;
  53.             } elseif ($month >= 20) {
  54.                 $year += 2000;
  55.                 $month -= 20;
  56.             } else {
  57.                 $year += 1900;
  58.             }
  59.  
  60.             if (substr($_POST['pesel'], 9, 10) % 2 == 1) {
  61.                 $sex = "mężczyzna";
  62.             } else {
  63.                 $sex = "kobieta";
  64.             }
  65.  
  66.             echo "Twoja data urodzenia to $day, $month $year<br>";
  67.             echo "Płeć: $sex";
  68.             echo $iscorrect;
  69.  
  70.         }
  71.  
  72.     } else {
  73.         echo "Błędne dane, pesel powinien zawierać same liczby<br>";
  74.     }
  75. }
  76.  
  77.  
  78. ?>
Advertisement
Add Comment
Please, Sign In to add comment