AlexKondov

Untitled

Aug 27th, 2014
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1. <?php
  2.     $name = $_GET['name'];
  3.     $gender = $_GET['gender'];
  4.     $pin = $_GET['pin'];
  5.  
  6.     $isCorrectMonth = true;
  7.     $nums = [2,4,8,5,10,9,7,3,6];
  8.     $card = [];
  9.  
  10.     $month = (int)$pin[2].$pin[3];
  11.  
  12.     if ($month > 12) {
  13.         if ($month - 20 >= 1 && $month - 20 <= 12) {
  14.             $isCorrectMonth = true;
  15.         }
  16.         else if ($month - 40 >= 1 && $month - 40 <= 12) {
  17.             $isCorrectMonth = true;
  18.         }
  19.         else {
  20.             $isCorrectMonth = false;       
  21.         }
  22.     }
  23.     else if ($month <= 12 && $month >= 1) {
  24.         $isCorrectMonth = true;
  25.     }
  26.     else {
  27.         $isCorrectMonth = false;
  28.     }
  29.  
  30.     if ($isCorrectMonth) {
  31.         if ($pin[8] % 2 === 0) {
  32.             $genderID = "male";
  33.         }
  34.         else {
  35.             $genderID = "female";
  36.         }
  37.     }
  38.     else {
  39.         echo "<h2>Incorrect data</h2>";
  40.         die();
  41.     }
  42.  
  43.     if ($genderID === $gender) {
  44.         $combo = 0;
  45.         for ($i=0; $i < count($nums); $i++) {
  46.             $combo += $nums[$i] * $pin[$i];
  47.         }
  48.         $combo = $combo % 11;
  49.         if ($combo === 10) {
  50.             $combo = 0;
  51.         }
  52.         if ($combo === (int)$pin[9]) {
  53.             $card['name'] = $name;
  54.             $card['gender'] = $gender;
  55.             $card['pin'] = $pin;
  56.             echo json_encode($card);
  57.         }
  58.         else {
  59.             echo "<h2>Incorrect data</h2>";
  60.             die();
  61.         }
  62.     }
  63.     else {
  64.         echo "<h2>Incorrect data</h2>";
  65.         die();
  66.     }
  67. ?>
Advertisement
Add Comment
Please, Sign In to add comment