Guest User

Untitled

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