Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2014
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. <?php //Start the Session
  2. session_start();
  3.  
  4. require('connect.php');
  5. if (isset($_POST['username']) and isset($_POST['password']))
  6. {
  7. //3.1.1 Assigning posted values to variables.
  8. $username = $_POST['username'];
  9. $password = $_POST['password'];
  10.  
  11. //3.1.2 Checking if the values exist in the database
  12. $checkLogin = $connection->query("SELECT * FROM users
  13. where (username='$username' && password='$password')");
  14. $numRows = $checkLogin->fetchColumn();
  15. //3.1.2 If the posted values are equal to the database values, then session will be created for the user.
  16. if ($numRows >= 1){
  17. $_SESSION['username'] = $username;
  18. }else{
  19. //3.1.3 If the login credentials doesn't match, he will be shown with an error message.
  20. echo '<script>window.alert("Invalid Login Credentials")</script>';
  21. }
  22. }
  23. //3.1.4 if the user is logged in Greets the user with message
  24. if (isset($_SESSION['username'])){
  25. $username = $_SESSION['username'];
  26. echo "Hi " . $username . "
  27. ";
  28. echo "This is the Members Area";
  29. echo "<a href='logout.php'>Logout</a>";
  30. echo $username;
  31.  
  32. }else{
  33. //3.2 When the user visits the page first time, simple login form will be displayed.
  34. ?>
  35. <!DOCTYPE html>
  36. <head>
  37. <title>CodingCyber - Simple Login Script</title>
  38. <link rel="stylesheet" type="text/css" href="style.css" />
  39. </head>
  40. <body>
  41. <!-- Form for logging in the users -->
  42.  
  43. <div class="register-form">
  44. <?php
  45. if(isset($msg) & !empty($msg)){
  46. echo $msg;
  47. }
  48. ?>
  49. <h1>Login</h1>
  50. <form action="login.php" method="POST">
  51. <p><label>User Name : </label>
  52. <input id="username" type="text" name="username" placeholder="username" /></p>
  53.  
  54. <p><label>Password&nbsp;&nbsp; : </label>
  55. <input id="password" type="password" name="password" placeholder="password" /></p>
  56.  
  57. <a class="btn" href="register.php">Signup</a>
  58. <input class="btn register" type="submit" name="submit" value="Login" />
  59. </form>
  60. </div>
  61. <?php } ?>
  62. </body>
  63. </html>
  64.  
  65. <?php
  66. session_start();
  67. $username = '';
  68. $password = '';
  69. $confirmPassword = '';
  70. $email = '';
  71. echo $username;
  72. unset($_POST['username']);
  73. unset($password);
  74.  
  75. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement