Advertisement
Guest User

Untitled

a guest
Oct 10th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. <?php
  2. session_start();
  3. ?>
  4.  
  5. <?php require_once("includes/connection.php"); ?>
  6. <?php include("includes/header.php"); ?>
  7.  
  8. <?php
  9.  
  10. if(isset($_SESSION["session_username"])){
  11. // echo "Session is set"; // for testing purposes
  12. header("Location: intropage.php");
  13. }
  14.  
  15. if(isset($_POST["login"])){
  16.  
  17. if(!empty($_POST['username']) && !empty($_POST['password'])) {
  18. $username=$_POST['username'];
  19. $password=$_POST['password'];
  20.  
  21. $query =mysqli_query("SELECT * FROM usertbl WHERE username='".$username."' AND password='".$password."'");
  22.  
  23. $numrows=mysqli_num_rows($query);
  24. if($numrows!=0)
  25.  
  26. {
  27. while($row=mysqli_fetch_assoc($query))
  28. {
  29. $dbusername=$row['username'];
  30. $dbpassword=$row['password'];
  31. }
  32.  
  33. if($username == $dbusername && $password == $dbpassword)
  34.  
  35. {
  36.  
  37.  
  38. $_SESSION['session_username']=$username;
  39.  
  40. /* Redirect browser */
  41. header("Location: intropage.php");
  42. }
  43. } else {
  44.  
  45. $message = "Invalid username or password!";
  46. }
  47.  
  48. } else {
  49. $message = "All fields are required!";
  50. }
  51. }
  52. ?>
  53.  
  54.  
  55.  
  56.  
  57. <div class="container mlogin">
  58. <div id="login">
  59. <h1>LOGIN</h1>
  60. <form name="loginform" id="loginform" action="" method="POST">
  61. <p>
  62. <label for="user_login">Username<br />
  63. <input type="text" name="username" id="username" class="input" value="" size="20" /></label>
  64. </p>
  65. <p>
  66. <label for="user_pass">Password<br />
  67. <input type="password" name="password" id="password" class="input" value="" size="20" /></label>
  68. </p>
  69. <p class="submit">
  70. <input type="submit" name="login" class="button" value="Log In" />
  71. </p>
  72. <p class="regtext">No account yet? <a href="register.php" >Register Here</a>!</p>
  73. </form>
  74.  
  75. </div>
  76.  
  77. </div>
  78.  
  79. <?php include("includes/footer.php"); ?>
  80.  
  81. <?php if (!empty($message)) {echo "<p class=\"error\">" . "MESSAGE: ". $message . "</p>";} ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement