Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8"/>
- </head>
- <body>
- <form action="" method="POST">
- <fieldset>
- <legend>PESEL DECODER</legend>
- <p>Pesel: <input name="pesel"></p>
- <p><input name="sub1" type="submit" value="Prześlij"></p>
- </fieldset>
- </form>
- </body>
- </html>
- <?php
- if (isset($_POST['sub1'])) {
- if (isset($_POST['pesel'])) {
- if (is_numeric($_POST['pesel'])) {
- $sum = 0;
- $weights = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3];
- for ($i = 0; $i < $_POST['pesel'] - 1; $i++) {
- $sum += substr($_POST['pesel'], $i, $i + 1) * $weights[$i];
- echo "test<br>";
- }
- echo "test2";
- $sum = $sum % 10;
- if ($sum == 10)
- $sum = 0;
- if ($sum == $_POST['pesel'][10])
- $iscorrect = true;
- else
- $iscorrect = false;
- $year = substr($_POST['pesel'], 0, 2);
- $month = substr($_POST['pesel'], 2, 4);
- $day = substr($_POST['pesel'], 4, 6);
- if ($month >= 80) {
- $year += 1800;
- $month -= 80;
- } elseif ($month >= 60) {
- $year += 2200;
- $month -= 60;
- } elseif ($month >= 40) {
- $year += 2100;
- $month -= 40;
- } elseif ($month >= 20) {
- $year += 2000;
- $month -= 20;
- } else {
- $year += 1900;
- }
- if (substr($_POST['pesel'], 9, 10) % 2 == 1) {
- $sex = "mężczyzna";
- } else {
- $sex = "kobieta";
- }
- echo "Twoja data urodzenia to $day, $month $year<br>";
- echo "Płeć: $sex";
- echo $iscorrect;
- }
- } else {
- echo "Błędne dane, pesel powinien zawierać same liczby<br>";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment