Advertisement
Guest User

Untitled

a guest
Jun 30th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.58 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. //Login form (index.php)
  5.  
  6. include "./system/controllers/db_connect.php";
  7. if(!$_POST['submit'])
  8. {
  9. ?>
  10.  
  11. <html>
  12. <head><link rel="stylesheet" href="style.css"></head>
  13.  
  14. <div class="divider">
  15.  
  16. <strong>Login</strong>
  17. <form method="post" action="index.php">
  18.  
  19. <div class="formElm">
  20. <label for="username">Username</label>
  21. <input id="username" type="text" name="username" maxlength="16">
  22. </div>
  23.  
  24. <div class="formElm">
  25. <label for="password">Password</label>
  26. <input type="password" name="password" maxlength="16">
  27. </div>
  28.  
  29. <input type="submit" name="submit" value="Login">
  30. </form>
  31. <a href="register.php">Register Here</a>
  32.  
  33. </div>
  34. </html>
  35.  
  36. <?php
  37. }
  38. else
  39. {
  40.   $user = protect($_POST['username']);
  41.   $pass = protect($_POST['password']);
  42.  
  43. if($user && $pass)
  44. {
  45. $pass = md5($pass); //compare the encrypted password
  46. $sql="SELECT account_id,name FROM `accounts` WHERE `name`='$user' AND `password`='$pass'";
  47. $query=mysql_query($sql) or die(mysql_error());
  48.  
  49.     if(mysql_num_rows($query) > 0)
  50.     {
  51.       $row = mysql_fetch_assoc($query);
  52.       $_SESSION['id'] = $row['account_id'];
  53.       $_SESSION['username'] = $row['name'];
  54.    
  55.       echo "<script type=\"text/javascript\">window.location=\"home.php\"</script>";   
  56.     }
  57.     else
  58.    {
  59.     echo "<script type=\"text/javascript\">
  60.     alert(\"Username and password combination is incorrect!\");
  61.     window.location=\"index.php\"</script>";
  62.    }   
  63. }
  64. else
  65. {          
  66.    echo "<script type=\"text/javascript\">
  67.     alert(\"You need to gimme a username AND password!\");
  68.     window.location=\"index.php\"</script>";
  69. }
  70. }
  71. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement