acbart

Untitled

Sep 30th, 2012
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.32 KB | None | 0 0
  1. <html>
  2.     <body>
  3.     <h1> Welcome. Please enter in a valid username and password.</h1>
  4.          
  5.         <form action="login2.php" method="post"><input type="hidden" name="ac" value="log">
  6.             UserName: <input type="text" name="username" /> <!--Enter in valid username -->
  7.             Password: <input type="password" name="password" /> <!--Enter in valid password -->
  8.             <input type="submit" value="Login"/> <!--submit username and password -->
  9.         </form>
  10.     </body>
  11. </html>
  12.  
  13.  
  14. <?php
  15. $USERS["username1"] = "password1";
  16. $USERS["username2"] = "password2";
  17. $USERS["username3"] = "password3";
  18.  
  19. function check_logged(){
  20.      global $_SESSION, $USERS;
  21.      if (!array_key_exists($_SESSION["logged"],$USERS)) {
  22.           header("Location: login.php");
  23.      };
  24. };
  25. ?>
  26.  
  27. <?php
  28. session_start(); /// initialize session
  29. include("password.php");
  30. check_logged();
  31. ?>
  32. <html>
  33.     <body>
  34.     Welcome, <?php echo $_POST["username"]; ?> 
  35.     <form action="view.php" action="LINK">
  36.         <input type="submit" value="View All Records">
  37.     </FORM>
  38.     </br>
  39.     <form action="addform.php" action="LINK">
  40.         <input type="submit" value="Add Records">
  41.     </FORM>
  42.     </br>
  43.     <form action="edit.php" action="LINK">
  44.         <input type="submit" value="Edit Records">
  45.     </FORM>
  46.     </br>
  47.     <form action="delete1.php" action="LINK">
  48.         <input type="submit" value="Delete Records">
  49.     </FORM>
  50.     </br>
  51.     </body>
  52.    
  53.  
  54. </html>
  55.  
  56. <?php
  57. //session_start();
  58. include("password.php");
  59.  
  60.  if ($_POST["ac"]=="log") { /// do after login form is submitted  
  61.      if ($USERS[$_POST["username"]]==$_POST["password"]) { /// check if submitted
  62.  
  63.           $_SESSION["logged"]=$_POST["username"];
  64.      } else {
  65.           echo 'Incorrect username/password. Please, try again.';
  66.      };
  67. };
  68. if (array_key_exists($_SESSION["logged"],$USERS)) { //// check if user is logged or not  
  69.      echo "You are logged in.";//// if user is logged show a message  
  70.      echo '<form action="home.php" method="post">';
  71.      echo   '<input type="submit" value="NEXT"/>';
  72. } else { //// if not logged show login form
  73.      echo '<form action="login2.php" method="post"><input type="hidden" name="ac" value="log"> ';
  74.      echo 'Username: <input type="text" name="username" />';
  75.      echo 'Password: <input type="password" name="password" />';
  76.      echo '<input type="submit" value="Login" />';
  77.      echo '</form>';
  78. };
  79.  
  80. ?>
Advertisement
Add Comment
Please, Sign In to add comment