Advertisement
Guest User

Untitled

a guest
Sep 21st, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.34 KB | None | 0 0
  1.  
  2. <?php
  3.    include("Config.php");
  4.    session_start();
  5.    
  6.    if($_SERVER["REQUEST_METHOD"] == "POST") {
  7.       if(empty($_POST['id']) || empty($_POST['password']) || empty($_POST['username'])) {
  8.           die('Id, Username, Password are not null!!!');
  9.       }
  10.       $id = $_POST['id'];
  11.       $username = mysqli_real_escape_string($db,$_POST['username']);
  12.       $password = mysqli_real_escape_string($db,$_POST['password']);
  13.       if(preg_match('/\s|[\(\)\'"\/\\=&\|1-9]|#|\/\*|into|file|case|group|where|order|offset|limit|and|or|not|null|union|select|from|when|--|;/i', $id))
  14.         die('Filter is working!!!!');
  15.       $sql = "SELECT `id` FROM `user` WHERE `id` = $id AND `password` = '$password'";
  16.       $result = mysqli_query($db,$sql) or die (mysqli_error($db));
  17.       $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
  18.       $count = mysqli_num_rows($result);
  19.       if($count == 1) {
  20.          $_SESSION['login_user'] = $username;
  21.          if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
  22.              $remote_ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  23.              $user_agent = $_SERVER['HTTP_USER_AGENT'];
  24.              if(preg_match('/[\/%#;-]|into|file|case|group|order|offset|limit|and|or|not|null|union|where|if|ascii|char|ord|case|when|div|mod|\+|\*|\&|\|/i', $remote_ip))
  25.                die('Filter is working!!!!');
  26.              if(preg_match('/[%#;-]|into|file|case|group|order|offset|limit|and|or|not|null|union|where|if|ascii|char|ord|case|when|div|mod|\+|\*|\&|\|/i', $user_agent))
  27.                die('Filter is working!!!!');
  28.              $user_id = $row['id'];
  29.              $sql_insert = "INSERT INTO `log`(`username`,`remote_ip`, `user_agent`) VALUES ('$username','$remote_ip','$user_agent')";
  30.              mysqli_query($db,$sql_insert) or die (mysqli_error($db));
  31.              $result = mysqli_affected_rows($db);
  32.              if($result > 0){
  33.                  //get log data
  34.                  $sql = "SELECT `username`, `remote_ip`, `user_agent` FROM `log` WHERE `username` = '$username' ORDER BY timestamp DESC LIMIT 1";
  35.                  $result = mysqli_query($db,$sql) or die (mysqli_error($db));
  36.                  $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
  37.                  $count = mysqli_num_rows($result);
  38.                  if($count == 1) {
  39.                      echo "[Log]- Remote IP: ".$row['remote_ip']." | User agent: ".$row['user_agent']." | Username: ".$row['username'];
  40.                  }
  41.              }
  42.              
  43.          }
  44.       }else {
  45.          $error = "Your Id or Password is invalid";
  46.          echo $error;
  47.       }
  48.       mysqli_close($db);
  49.    }
  50. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement