Advertisement
Guest User

Untitled

a guest
Jul 6th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1. <?php
  2.  
  3.     session_start();
  4.    
  5.     if (!isset($_SESSION['inicjuj']))
  6.     {
  7.         session_regenerate_id();
  8.         $_SESSION['inicjuj'] = true;
  9.         $_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
  10.     }
  11.    
  12.     if($_SESSION['ip'] != $_SERVER['REMOTE_ADDR'])
  13.     {
  14.         die('');   
  15.     }
  16.    
  17.     if(isset($_POST['username'])) {
  18.    
  19.     $username = $_POST['username'];
  20.     $username = $mysqli->real_escape_string($username);
  21.     $userpassword = md5($_POST['password']);
  22.  
  23.    
  24.     $query = "SELECT id, nazwa, haslo FROM uzytkownicy WHERE nazwa='" .$username. "'";
  25.    
  26.     if(!$result = $mysqli->query($query)) {
  27.         die ($mysqli->error);
  28.     } else {
  29.         if($row_cnt = $result->num_rows == 0) {
  30.             echo ("No user!");
  31.         } else {
  32.             $row = $result->fetch_assoc();
  33.             if($userpassword == $row['haslo']) {
  34.                 $_SESSION['id'] = $row['id'];
  35.             } else {
  36.                 die ('wrong user or pass');
  37.             }
  38.         }
  39.     }
  40.     }
  41.    
  42.     if(!isset($_SESSION['id'])) {
  43.    
  44.         echo '<form method="post" action="index.php">
  45.         Login: <input type="text" name="username"/>
  46.        <input type="password" name="password"/>
  47.         <input type="submit" value="OK"/></form>';
  48.         exit;
  49.     }
  50.  
  51. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement