Advertisement
Guest User

Untitled

a guest
Jan 10th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1.  
  2. <?php
  3. session_start();
  4.  
  5. if (isset($_POST['submit'])) {
  6.  
  7. // Include the databas connection script
  8. include_once("db.php");
  9.  
  10. // Set the posted data from the form into local variables
  11. $usname = ($_POST['username']);
  12. $paswd = ($_POST['password']);
  13.  
  14. $usname = mysqli_real_escape_string($dbCon, $usname);
  15. $paswd = mysqli_real_escape_string($dbCon, $paswd);
  16.  
  17. $paswd = md5($paswd); // using md5 just for testing purposes
  18.  
  19. $sql = "SELECT id, username, password FROM members WHERE username = '$usname' AND activated = '1' LIMIT 1";
  20. $query = mysqli_query($dbCon, $sql);
  21. $row = mysqli_fetch_row($query);
  22.  
  23. $uid = $row[0];
  24. $dbUsname = $row[1];
  25. $dbPassword = $row[2];
  26.  
  27. // Check if the username and the password they entered was correct
  28. if ($usname == $dbUsname && $paswd == $dbPassword) {
  29. // Set session
  30. $_SESSION['username'] = $usname;
  31. $_SESSION['id'] = $uid;
  32. // Now direct to users feed
  33. header("Location: user.php");
  34. } else {
  35. echo "Must log in!";
  36. }
  37.  
  38. }
  39. ?>
  40.  
  41. <!DOCTYPE html>
  42. <html>
  43. <head>
  44. <meta charset="UTF-8">
  45. <title>Basic login system</title>
  46. <style type="text/css">
  47. html {
  48. font-family: Verdana, Geneva, sans-serif;
  49. }
  50. h1 {
  51. font-size: 24px;
  52. text-align: center;
  53. }
  54. #wrapper {
  55. position: absolute;
  56. width: 100%;
  57. top: 30%;
  58. margin-top: -50px;/* half of #content height*/
  59. }
  60. #form {
  61. margin: auto;
  62. width: 200px;
  63. height: 100px;
  64. }
  65. </style>
  66. </head>
  67.  
  68. <body>
  69. <div id="wrapper">
  70. <h1>Simple PHP Login</h1>
  71. <form id="form" action="index.php" method="post" enctype="multipart/form-data">
  72. Username: <input type="text" name="username" /> <br />
  73. Password: <input type="password" name="password" /> <br />
  74. <input type="submit" value="Login" name="submit" />
  75. </form>
  76. </body>
  77. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement