Advertisement
HedgeTheHog

Untitled

Oct 22nd, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.61 KB | None | 0 0
  1.  
  2. <?php  //Start the Session
  3. session_start();
  4.  require('connect.php');
  5. //3. If the form is submitted or not.
  6. //3.1 If the form is submitted
  7. if (isset($_POST['username']) and isset($_POST['password'])){
  8. //3.1.1 Assigning posted values to variables.
  9. $username = $_POST['username'];
  10. $password = $_POST['password'];
  11. //3.1.2 Checking the values are existing in the database or not
  12. $query = "SELECT * FROM `user` WHERE username='$username' and password='$password'";
  13.  
  14. $result = mysqli_query($connection, $query) or die(mysqli_error($connection));
  15. $count = mysqli_num_rows($result);
  16. //3.1.2 If the posted values are equal to the database values, then session will be created for the user.
  17. if ($count == 1){
  18. $_SESSION['username'] = $username;
  19. }else{
  20. //3.1.3 If the login credentials doesn't match, he will be shown with an error message.
  21. $fmsg = "Invalid Login Credentials.";
  22. }
  23. }
  24. //3.1.4 if the user is logged in Greets the user with message
  25. if (isset($_SESSION['username'])){
  26. $username = $_SESSION['username'];
  27. echo "Hai " . $username . "
  28. ";
  29. echo "This is the Members Area
  30. ";
  31. echo "<a href='logout.php'>Logout</a>";
  32.  
  33. }else{
  34. //3.2 When the user visits the page first time, simple login form will be displayed.
  35. ?>
  36. <html>
  37. <head>
  38.     <title>User Login Using PHP & MySQL</title>
  39.    
  40. <!-- Latest compiled and minified CSS -->
  41. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" >
  42.  
  43. <!-- Optional theme -->
  44. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" >
  45.  
  46. <link rel="stylesheet" href="styles.css" >
  47.  
  48. <!-- Latest compiled and minified JavaScript -->
  49. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  50. </head>
  51. <body>
  52.  
  53. <div class="container">
  54.       <form class="form-signin" method="POST">
  55.       <?php if(isset($fmsg)){ ?><div class="alert alert-danger" role="alert"> <?php echo $fmsg; ?> </div><?php } ?>
  56.         <h2 class="form-signin-heading">Please Login</h2>
  57.         <div class="input-group">
  58.       <span class="input-group-addon" id="basic-addon1">@</span>
  59.       <input type="text" name="username" class="form-control" placeholder="Username" required>
  60.     </div>
  61.         <label for="inputPassword" class="sr-only">Password</label>
  62.         <input type="password" name="password" id="inputPassword" class="form-control" placeholder="Password" required>
  63.         <button class="btn btn-lg btn-primary btn-block" type="submit">Login</button>
  64.         <a class="btn btn-lg btn-primary btn-block" href="register.php">Register</a>
  65.       </form>
  66. </div>
  67.  
  68. </body>
  69.  
  70. </html>
  71. <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement