Advertisement
gayanov

Untitled

Mar 24th, 2017
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.12 KB | None | 0 0
  1. <?php
  2. session_start();
  3.   include "../config.php";
  4.   include "../functions/getCurlData.php";
  5.   //include "../classes/user.php";
  6. //DB::init();
  7.  
  8. if ( ! empty($_POST['login']) AND ! empty($_POST['password']) AND !empty($_POST['g-recaptcha-response']))
  9. {
  10.  
  11.    $param = $db->prepare('SELECT * from `users` WHERE `login` = ? AND `password` = ? AND `activation` = 1;');
  12.    //array(1=>$_POST['login'], 2=>$_POST['password']));
  13.     $hashpassw = hash_hmac('sha256', ''.$_POST['password'].'', '4tbmagkILMTV5fBGNpuTxqQq1ywgZIiulilSMPj5e15B');
  14.  
  15.    if ( ! $param->bindParam(1, $_POST['login'], PDO::PARAM_STR, 50))
  16.    {
  17.       exit('<script>
  18.         toastr.error("Слишком длиный логин!")</script>');
  19.    }
  20.    elseif ( ! $param->bindParam(2, $hashpassw, PDO::PARAM_STR, 50))
  21.    {
  22.       exit('<script>
  23.         toastr.error("Слишком длиный пароль!")</script>');
  24.    }
  25.     $recaptcha=$_POST['g-recaptcha-response'];
  26.     if($recaptcha !== NULL)
  27.     {
  28.         include("getCurlData.php");
  29.         $google_url="https://www.google.com/recaptcha/api/siteverify";
  30.         $secret='6LcyHhoUAAAAAIOYrBhhwNb52trdwV3EkYSDr0kU';
  31.         $ip=$_SERVER['HTTP_CF_CONNECTING_IP'];
  32.         $url=$google_url."?secret=".$secret."&response=".$recaptcha."&remoteip=".$ip;
  33.         $res=getCurlData($url);
  34.         $res= json_decode($res, true);
  35.         //echo var_dump($res);
  36.         //reCaptcha введена
  37.         if($res['success'])
  38.         {
  39.             echo "ok";
  40.         }
  41.         /*if($res['success'] == "false"){
  42.         echo "<script>
  43.         toastr.error('Подтвердите, что вы не робот!')</script>";
  44.         }*/
  45.     }
  46.     if($recaptcha === NULL){
  47.         echo "ok";
  48.     }
  49.    if ($param->execute())
  50.    {
  51.       $param->setFetchMode(PDO::FETCH_ASSOC);
  52.      
  53.       if ($result = $param->fetchAll())
  54.       {
  55.          // Станет доступно
  56.          // $result[0]['id'];
  57.          // $result[0]['login'];
  58.          // $result[0]['password'];
  59.          // $result[0]['email'];
  60.          // $result[0]['ip'];
  61.          // $result[0]['lastlogin'];
  62.          // $result[0]['activation'];
  63.          //$has_pass = hash_hmac('sha256', 'wefffewewf', 'ewfewewew');
  64.  
  65.     //echo $hashpassw;
  66.    /*if(){
  67.    }*/
  68.   date_default_timezone_set("UTC"); // Устанавливаем часовой пояс по Гринвичу
  69.   $time = time(); // Вот это значение отправляем в базу
  70.   $offset = 3; // Допустим, у пользователя смещение относительно Гринвича составляет +3 часа
  71.   $time += 3 * 3600; // Добавляем 3 часа к времени по Гринвичу
  72.   $last_login_datetime = date("Y-m-d H:i:s", $time); // Выводим время пользователя, согласно его часовому поясу
  73.    //$last_login_datetime = time();
  74.    $param1 = $db->prepare('UPDATE `users` SET `last_login_datetime`= ? WHERE `login` = ?');
  75.  
  76.    $param1->bindParam(1, $last_login_datetime, PDO::PARAM_STR);
  77.    $param1->bindParam(2, $_POST['login'], PDO::PARAM_STR);
  78.    if ($param1->execute())
  79.    {
  80.       $param1->setFetchMode(PDO::FETCH_ASSOC);
  81.      
  82.       //if ($result1 = $param1->fetchAll())
  83.       //{
  84.          // Станет доступно
  85.          // $result[0]['id'];
  86.          // $result[0]['login'];
  87.          // $result[0]['password'];
  88.          // $result[0]['email'];
  89.          // $result[0]['ip'];
  90.          // $result[0]['lastlogin'];
  91.          // $result[0]['activation'];
  92.  
  93.          $_SESSION['login']=$_POST['login'];
  94.          exit('<script>
  95.         toastr.success("Вы успешно авторизовались!")
  96.         </script>
  97.         <meta HTTP-EQUIV="refresh" content="1"; URL="'.$settings['urlsite'].'/panel">');
  98.         //document.location.href = "'.$settings['urlsite'].'/panel";
  99.         //header('Location:'.$settings['urlsite'].'/panel');
  100.       //}
  101.    }
  102.    }
  103.       else exit ('<script>
  104.         toastr.error("Нету такого пользователя или ваша учётная запись ещё не активирована!")</script>');
  105.    }
  106.    
  107. }
  108. else exit ('<script>
  109.         toastr.error("Заполните все поля!")</script>');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement