Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.08 KB | None | 0 0
  1.     public function insert_user($respon){
  2.         try {
  3.             $recaptcha=$respon['g-recaptcha-response'];
  4.             if(!empty($recaptcha)) {
  5.                 $google_url = "https://www.google.com/recaptcha/api/siteverify";
  6.                 $secret = '6Ld9134UAAAAAKDtW4t5WswxaNo6nRsT6UopGPSM';
  7.                 $ip = $_SERVER['REMOTE_ADDR'];
  8.                 $url = $google_url . "?secret=" . $secret . "&response=" . $recaptcha . "&remoteip=" . $ip;
  9.                 $res = $this->getCurlData($url);
  10.                 $res = json_decode($res, true);
  11.                 //reCaptcha введена
  12.                 if ($res['success']) {
  13.                     $r['log'] = $this->replace_attr($respon['log']);
  14.                     $r['pas'] = $this->replace_attr_md5($respon['pas']);
  15.                     $r['nam'] = $this->replace_attr($respon['nam']);
  16.                     $r['tel'] = $this->replace_attr($respon['tel']);
  17.                     $r['mail'] = $this->replace_attr($respon['mail']);
  18.                     $r['org'] = $this->replace_attr($respon['org']);
  19.                     $r['status'] = 0;
  20.                     $r['adres'] = $this->replace_attr($respon['adres']);
  21.                     $q = $this->dbs->prepare("select * from users where login=:login;");
  22.                     $q->execute([':login' => $r['log']]);
  23.                     if ($q->rowCount() != 0) {
  24.                         echo json_encode(array("naz" => "Сообщение", "mes" => "Пользователь с таким логином уже существует"), JSON_UNESCAPED_UNICODE);
  25.                     } else {
  26.                         #print "insert into users(login, pasw, nam, tel, adres, mail, status, org) values(" . $r['log'] . ", " . $r['pas'] . ", " . $r['nam'] . ", " . $r['tel'] . ", " . $r['adres'] . ", " . $r['mail'] . ", " . $r['status'] . ", " . $r['org'] . ");";
  27.                        $s = $this->dbs->prepare("insert into users(login, pasw, nam, tel, adres, mail, status, org) values(:login, :pasw, :nam, :tel, :adres, :mail, :status, :org);");
  28.                         if ($s->execute([':login' => $r['log'], ':pasw' => $r['pas'], ':nam' => $r['nam'], ':tel' => $r['tel'], ':adres' => $r['adres'], ':mail' => $r['mail'], ':status' => $r['status'], ':org' => $r['org']])) {
  29.                             echo json_encode(array("naz" => "Сообщение:", "mes" => "Пользователь успешно зарегистрирован"), JSON_UNESCAPED_UNICODE);
  30.                         } else echo json_encode(array("naz"=>"Сообщение:", "mes" => "Произошла ошибка при регистрации пользователя"), JSON_UNESCAPED_UNICODE);
  31.                     }
  32.                 }else echo json_encode(array("naz" => "Сообщение:", "mes" => "Пожалуйста повторите ввод reCAPTCHA"), JSON_UNESCAPED_UNICODE);
  33.             }else echo json_encode(array("naz" => "Сообщение:", "mes" => "Пожалуйста повторите ввод reCAPTCHA"), JSON_UNESCAPED_UNICODE);
  34.         } catch (PDOException $e) {
  35.             print $e;
  36.         }
  37.  
  38.  
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement