Advertisement
Guest User

Untitled

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