Advertisement
Guest User

Untitled

a guest
Oct 14th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.56 KB | None | 0 0
  1. <?php
  2. if(isset($_POST["username"]))
  3. {
  4.     $user = $_POST["username"];
  5. } else {
  6.     $user = "";
  7. }
  8. if(isset($_POST["password"]))
  9. {
  10.     $password = $_POST["password"];
  11. } else {
  12.     $password = "";
  13. }
  14. $validated = false;
  15. session_start();
  16. if($user!=""&&$password!="")
  17. {
  18.     if($user=="jsmith"&&$password=="letmein")
  19.         $validated = true;
  20.     if($validated) {
  21.         $_SESSION['login'] = "OK";
  22.         $_SESSION['username'] = $user;
  23.         $_SESSION['password'] = $password;
  24.         header('Location: protected.php');
  25.     }
  26.     else
  27.     { $_SESSION['login'] = "";
  28.         echo "Invalid username or password.";
  29.  
  30.     }
  31. }
  32. else $_SESSION['login'] = "";
  33. ?>
  34.  
  35. <html>
  36. <body>
  37. <h1>Login Page</h1>
  38. <p>Please enter your
  39.     username and password:</p>
  40. <form action="login.php"
  41.       method="post">
  42.     <table>
  43.         <tr>
  44.             <td
  45.                 align="right">Username: </td>
  46.             <td><input
  47.                     size=\"20\" type="text"
  48.                     size="20" maxlength="15"
  49.                     name="username"></td>
  50.         </tr>
  51.         >
  52.         <tr>
  53.             <td
  54.                 align="right">Password: </td>
  55.             <td><input
  56.                     size=\"20\" type="password"
  57.                     size="20" maxlength="15"
  58.                     name="password"></td>
  59.         </tr>
  60.         <tr>
  61.             <td> </td>
  62.             <td colspan="2"
  63.                 align="left"><input
  64.                     type="submit"
  65.                     value="Login"></td>
  66.         </tr>
  67.     </table>
  68. </form>
  69. </body>
  70. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement