Advertisement
Guest User

Untitled

a guest
Jun 20th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * @author Jason
  5. * @copyright 2010
  6. */
  7.  
  8. session_start();
  9.  
  10. if ( isset( $_SESSION['username'] ) && isset( $_SESSION['password'] ) )
  11. {
  12.  
  13. echo "Welcome ".$_SESSION['username']."! Click here to logout.";
  14.  
  15. }
  16. else
  17. {
  18.  
  19. $username = $_POST['username'];
  20. $password = $_POST['password'];
  21. $submit = $_POST['submit'];
  22.  
  23. if ( isset($submit))
  24. {
  25.  
  26. if ( $username && $password )
  27. {
  28.  
  29. include "connect.php";
  30.  
  31. $query = mysql_query(" SELECT * FROM users WHERE username = '$username' ");
  32.  
  33. $numrows = mysql_num_rows( $query );
  34.  
  35. if ($numrows!=0)
  36. {
  37.  
  38. while ( $r = mysql_fetch_assoc( $query ) )
  39. {
  40.  
  41. $dbusername = $r['username'];
  42. $dbpassword = $r['password'];
  43.  
  44. }
  45.  
  46. if ( $username == $dbusername && $password == $dbpassword )
  47. {
  48.  
  49. $_SESSION['username'] = $username;
  50. $_SESSION['password'] = $password;
  51.  
  52. }
  53. else
  54. {
  55. echo "Incorrect Password";
  56. }
  57.  
  58. }
  59. else
  60. {
  61. echo "Username is taken!";
  62. }
  63.  
  64. }
  65. else
  66. {
  67. echo "Please enter a username and password.";
  68. }
  69.  
  70.  
  71. }
  72.  
  73. ?>
  74.  
  75. <html>
  76.  
  77. <form method='post' action="">
  78.  
  79. Username: <input type="text" name="username"/><br />
  80. Password: <input type="password" name="password"/><br />
  81.  
  82. <input type="submit" value="Log in" name="submit" />
  83.  
  84. </form>
  85.  
  86. </html>
  87.  
  88. <?php
  89.  
  90. }
  91.  
  92. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement