Advertisement
Guest User

Untitled

a guest
Aug 14th, 2017
67
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 2011
  6. */
  7.  
  8. session_start();
  9.  
  10. include 'config.php';
  11.  
  12. if ( isset( $_SESSION['username'] ) && isset( $_SESSION['password'] ) ) {
  13.  
  14. echo '
  15. Welcome <strong>'. $_SESSION['username'] .'</strong> !
  16. <br />
  17. <a href="logout.php">Logout</a>
  18. ';
  19.  
  20. } else {
  21.  
  22. if ( isset( $_POST['submit'] ) ) {
  23.  
  24. $username = $_POST['username'];
  25. $password = $_POST['password'];
  26.  
  27. if ( $username && $password ) {
  28.  
  29. $query = mysql_query( " SELECT * FROM users WHERE `username` = '$username' " );
  30. $numrows = mysql_num_rows( $query );
  31.  
  32. if ( $numrows ) {
  33.  
  34. while ( $r = mysql_fetch_assoc( $query ) ) {
  35.  
  36. $db_username = $r['username'];
  37. $db_password = $r['password'];
  38.  
  39. }
  40.  
  41. if ( $db_username == $username && $db_password == $password ) {
  42.  
  43. $_SESSION['username'] = $username;
  44. $_SESSION['password'] = $password;
  45.  
  46. echo "<div style='background-color: lightgreen'><meta http-equiv='refresh' content='2'>You have now been logged in, please wait while you're being redirected.</div>";
  47.  
  48. } else {
  49.  
  50. echo "<div style='background-color: red'>Incorrect password.</div>";
  51.  
  52. }
  53.  
  54. } else {
  55.  
  56. echo 'Incorrect username.';
  57.  
  58. }
  59.  
  60. } else {
  61.  
  62. echo 'Please enter a valid username and password.';
  63.  
  64. }
  65.  
  66.  
  67. } ?>
  68.  
  69. <form method="POST" action="">
  70. Username: <input type="text" name="username" value="<?php echo $_POST['username'] ?>"/> <br />
  71. Password: <input type="text" name="password"/> <br />
  72. <input type="submit" name="submit"/>
  73. </form>
  74.  
  75. <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement