Advertisement
Guest User

Untitled

a guest
Jan 10th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. <?php
  2. /*
  3. Author: Javed Ur Rehman
  4. Website: https://htmlcssphptutorial.wordpress.com
  5. */
  6. ?>
  7. <!DOCTYPE html>
  8. <html>
  9. <head>
  10. <meta charset="utf-8">
  11. <title>Login</title>
  12. <link rel="stylesheet" href="includes/style2.css" />
  13. </head>
  14. <body>
  15. <?php
  16. require('db.php');
  17. session_start();
  18. // If form submitted, insert values into the database.
  19. if (isset($_POST['username'])){
  20. $username = $_POST['username'];
  21. $password = $_POST['password'];
  22. $username = stripslashes($username);
  23. $username = mysql_real_escape_string($username);
  24. $password = stripslashes($password);
  25. $password = mysql_real_escape_string($password);
  26. //Checking is user existing in the database or not
  27. $query = "SELECT * FROM `users` WHERE username='$username' and password='".md5($password)."'";
  28. $result = mysql_query($query) or die(mysql_error());
  29. $rows = mysql_num_rows($result);
  30. if($rows==1){
  31. $_SESSION['username'] = $username;
  32. header("Location: index.php"); // Redirect user to index.php
  33. }else{
  34. echo "<div class='form'><h3>Username/password is incorrect.</h3><br/>Click here to <a href='login.php'>Login</a></div>";
  35. }
  36. }else{
  37. ?>
  38. <div class="form">
  39. <h1>Log In</h1>
  40. <form action="" method="post" name="login">
  41. <input type="text" name="username" placeholder="Username" required />
  42. <input type="password" name="password" placeholder="Password" required />
  43. <input name="submit" type="submit" value="Login" />
  44. </form>
  45. <p>Not registered yet? <a href='registration.php'>Register Here</a></p>
  46. </div>
  47. <?php } ?>
  48. </body>
  49. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement