Advertisement
Guest User

Untitled

a guest
Jun 20th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * @author Jason
  5. * @copyright 2010
  6. */
  7.  
  8. session_start();
  9.  
  10. include "connect.php";
  11.  
  12. if ( isset( $_SESSION['username'] ) && isset( $_SESSION['password'] ) )
  13. {
  14.  
  15. echo "Welcome ".$_SESSION['username']."! Click <a href='logout.php'>here</a> to logout.";
  16.  
  17. }
  18. else
  19. {
  20.  
  21. $username = mysql_real_escape_string( strtolower( $_POST['username'] ) );
  22. $password = mysql_real_escape_string( $_POST['password'] );
  23. $submit = $_POST['submit'];
  24.  
  25. if ( isset( $_POST['submit'] ))
  26. {
  27.  
  28. if ( $username && $password )
  29. {
  30.  
  31. $query = mysql_query(" SELECT * FROM users WHERE username = '$username' ");
  32.  
  33. $numrows = mysql_num_rows( $query );
  34.  
  35. if ( $numrows )
  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 && md5( $password ) == $dbpassword )
  47. {
  48.  
  49. $_SESSION['username'] = $username;
  50. $_SESSION['password'] = $password;
  51.  
  52. echo "<meta http-equiv='refresh' content='2'>You have now been logged in, please wait while you're being redirected.";
  53.  
  54. }
  55. else
  56. {
  57. echo "Incorrect Password";
  58. }
  59.  
  60. }
  61. else
  62. {
  63. echo "Username is taken!";
  64. }
  65.  
  66. }
  67. else
  68. {
  69. echo "Please enter a username and password.";
  70. }
  71.  
  72.  
  73. }
  74.  
  75. ?>
  76.  
  77. <html>
  78.  
  79. <form method='post' action="">
  80.  
  81. Username: <input type="text" name="username"/><br />
  82. Password: <input type="password" name="password"/><br />
  83.  
  84. <input type="submit" value="Log in" name="submit" />
  85.  
  86. </form>
  87.  
  88. </html>
  89.  
  90. <a href="register.php">Register An Account</a>
  91.  
  92. <?php
  93.  
  94. }
  95.  
  96. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement