Guest User

Untitled

a guest
Sep 7th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.02 KB | None | 0 0
  1. <?php
  2. session_start();
  3. include("passwords.php");
  4. if ($_POST["ac"]=="log") { /// do after login form is submitted  
  5.      if ($USERS[$_POST["username"]]==$_POST["password"]) { /// check if submitted username and password exist in $USERS array
  6.           $_SESSION["logged"]=$_POST["username"];
  7.      } else {
  8.           echo 'Incorrect username/password. Please try again.';
  9.      };
  10. };
  11. if (array_key_exists($_SESSION["logged"],$USERS)) { //// check if user is logged or not  
  12.      echo "You are logged in."; //// if user is logged show a message  
  13. } else { //// if not logged show login form
  14.      echo '<form action="default.php" method="post"><input type="hidden" name="ac" value="log"> ';
  15.      echo 'Username: <input type="text" name="username" />';
  16.      echo 'Password: <input type="password" name="password" />';
  17.      echo '<input type="submit" value="Login" onClick="location.href=\'index.html\'"/>';
  18.      echo '</form>';
  19. };
  20. ?>
  21.  
  22. Error: Notice: Undefined index: ac in C:\xampp\htdocs\default.php on line 4
Add Comment
Please, Sign In to add comment