Advertisement
Guest User

Untitled

a guest
Apr 10th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. Login.php
  2. <?php
  3. include('Verifylog.php'); // Includes Login Script
  4. if(isset($_SESSION['login_user'])){
  5. header("location:../profile.php");
  6. }
  7. ?>
  8. <!DOCTYPE html>
  9. <html>
  10. <head>
  11. <title>de novo</title>
  12. <link href="style.css" rel="stylesheet" type="text/css">
  13. </head>
  14. <body>
  15. <div id="main">
  16. <div id="login">
  17. <h2>Login</h2>
  18. <form action="" method="post">
  19. <label>UserName :</label>
  20. <input id="name" name="username" placeholder="username"
  21. type="text">
  22. <label>Password :</label>
  23. <input id="password" name="password" placeholder="**********"
  24. type="password">
  25. <input name="submit" type="submit" value=" Login ">
  26. <span><?php echo $error; ?></span>
  27. </form>
  28. </div>
  29. </div>
  30. </body>
  31. </html>
  32.  
  33. <?php
  34. session_start(); // Starting Session
  35. $error=''; // Variable To Store Error Message
  36. if (isset($_POST['submit'])) {
  37. if (empty($_POST['username']) || empty($_POST['password'])) {
  38. $error = "Username or Password is invalid";
  39. }
  40. else
  41. {
  42. // Define $username and $password
  43. $username=$_POST['username'];
  44. $password=$_POST['password'];
  45. // Establishing Connection with Server by passing server_name,
  46. user_id and password as a parameter
  47. $connection = mysql_connect("localhost", "root", "");
  48. // To protect MySQL injection for Security purpose
  49. $username = stripslashes($username);
  50. $password = stripslashes($password);
  51. $username = mysql_real_escape_string($username);
  52. $password = mysql_real_escape_string($password);
  53. // Selecting Database
  54. $db = mysql_select_db("denovo", $connection);
  55. // SQL query to fetch information of registerd users and finds
  56. user match.
  57. $query = mysql_query("select * from login where
  58. password='$password' AND username='$username'", $connection);
  59. $rows = mysql_num_rows($query);
  60. if ($rows == 1) {
  61. $_SESSION['login_user']=$username; // Initializing Session
  62. header("location:../profile.php"); // Redirecting To Other Page
  63. } else {
  64. $error = "Username or Password is invalid";
  65. }
  66. mysql_close($connection); // Closing Connection
  67. }
  68. }
  69. ?>
  70.  
  71. <?php
  72. // Establishing Connection with Server by passing server_name,
  73. user_id and password as a parameter
  74. $connection = mysql_connect("localhost", "root", "");
  75. // Selecting Database
  76. $db = mysql_select_db("denovo", $connection);
  77. session_start();// Starting Session
  78. // Storing Session
  79. $user_check=$_SESSION['login_user'];
  80. // SQL Query To Fetch Complete Information Of User
  81. $ses_sql=mysql_query("select username from login where
  82. username='$user_check'", $connection);
  83. $row = mysql_fetch_assoc($ses_sql);
  84. $login_session =$row['username'];
  85. if(!isset($login_session)){
  86. mysql_close($connection); // Closing Connection
  87. header('Location:login.php'); // Redirecting To Home Page
  88. }
  89. ?>
  90.  
  91. table login
  92. id
  93. username
  94. password
  95. session_id
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement