Advertisement
Guest User

Untitled

a guest
Jul 1st, 2015
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.39 KB | None | 0 0
  1.  
  2. <?php
  3. session_start();
  4. $showmessage = '';
  5.  
  6. if(isset($_POST['submit'])) {
  7.  
  8.    
  9.     $username = $_POST['username'];
  10.     $password = $_POST['password'];
  11.  
  12.     $connection = mysqli_connect("localhost", "root", "", "sedctest");
  13.     if(mysqli_connect_errno()) {
  14.         die('Ne moze da se konektira so baza');
  15.     }
  16.  
  17.    
  18.     $password = sha1($password);
  19.  
  20.    
  21.     $query  = "SELECT * ";
  22.     $query .= "FROM users ";
  23.     $query .= "WHERE korisnicko_ime = '{$username}' AND lozinka = '{$password}' ";
  24.     $query .= "LIMIT 1";
  25.  
  26.  
  27.     $admin_set = mysqli_query($connection, $query);
  28.  
  29.    
  30.     if(!$admin_set) {
  31.         $showmessage = "Problem pri izvrsuvanje na query!" . mysqli_error($connection);
  32.     }
  33.    
  34.     else {
  35.        
  36.         $admin = mysqli_fetch_assoc($admin_set);
  37.    
  38.         mysqli_free_result($admin_set);
  39.  
  40.    
  41.         if($admin) {
  42.            
  43.             $_SESSION['user_id'] = $admin['idd'];
  44.            
  45.             header('Location: applications.php');
  46.  
  47.         }
  48.        
  49.         else {
  50.             $showmessage = "Greshni username/password";
  51.         }
  52.  
  53.     }
  54.  
  55.    
  56.     mysqli_close($connection);
  57.  
  58.    
  59. }
  60.  
  61. ?>
  62.  
  63.  
  64. <html>
  65. <head>
  66.     <title>Login</title>
  67. </head>
  68. <body>
  69.    
  70.     <form method="POST">
  71.         <p>
  72.             <label for="username">Username</label>
  73.             <input type="text" id="username" name="username" />
  74.         </p>
  75.         <p>
  76.             <label for="username">Author</label>
  77.             <input type="text" id="password" name="password" />
  78.         </p>
  79.         <p>        
  80.             <input type="submit"  name="submit" value="Submit" />
  81.         </p>
  82.     </form>
  83. </body>
  84. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement