Advertisement
Guest User

Untitled

a guest
Apr 20th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.91 KB | None | 0 0
  1. <?php include 'header.php';
  2.     include 'WebsiteUser.php';
  3. ?>
  4.  
  5. <?php
  6.     session_start();
  7.     if(isset($_SESSION['websiteUser'])){
  8.         if($_SESSION['websiteUser']->isAuthenticated()){
  9.             session_write_close();
  10.             header('Location:internal.php');
  11.         }else{
  12.              header('Location:login.php');
  13.         }
  14.     }
  15.     $missingFields = false;
  16.     if(isset($_POST['submit'])){
  17.  
  18.         if(isset($_POST['username']) && isset($_POST['password'])){
  19.             if($_POST['username'] == "" || $_POST['password'] == ""){
  20.                 $missingFields = true;
  21.             } else {
  22.                 //All fields set, fields have a value
  23.                
  24.                 $websiteUser = new WebsiteUser();
  25.                 if(!$websiteUser->hasDbError()){
  26.                
  27.                     $username = $_POST['username'];
  28.                     $password = $_POST['password'];
  29.                     $websiteUser->authenticate($username, $password);
  30.  
  31.                     ////////////////////////////////////////NOT HAPPENING
  32.                     if($websiteUser->isAuthenticated()){
  33.                         $_SESSION['websiteUser'] = $websiteUser;
  34.                         header('Location:internal.php');
  35.                     }else{
  36.                         header('Location:login.php');
  37.                     }
  38.                 }
  39.             }
  40.         }
  41.     }
  42. ?>
  43.  
  44. <!DOCTYPE html>
  45. <html>
  46.     <head>
  47.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  48.         <title>login</title>
  49.     </head>
  50.     <body>
  51.         <!-- MESSAGES -->
  52.         <?php
  53.             //Missing username/password
  54.             if($missingFields){
  55.                 echo '<h3 style="color:red;">Please enter both a username and a password</h3>';
  56.             }
  57.            
  58.             //Authentication failed
  59.             if(isset($websiteUser)){
  60.                 if(!$websiteUser->isAuthenticated()){
  61.                     echo '<h3 style="color:red;">Login failed. Please try again.</h3>';
  62.                 }
  63.             }
  64.         ?>
  65.        
  66.         <form name="login" id="login" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" style="padding:20px;">
  67.         <table>
  68.             <tr>
  69.                 <td>Username:</td>
  70.                 <td><input type="text" name="username" id="username"></td>
  71.             </tr>
  72.             <tr>
  73.                 <td>Password:</td>
  74.                 <td><input type="password" name="password" id="password"></td>
  75.             </tr>
  76.             <tr>
  77.                 <td><input type="submit" name="submit" id="submit" value="Login"></td>
  78.                 <td><input type="reset" name="reset" id="reset" value="Reset"></td>
  79.             </tr>
  80.         </table>
  81.             <div style="text-align:center;"><?php echo '<p>Session ID: ' . session_id() . '</p>';?></div>
  82.         </form>
  83.         <br/><br/><br/><br/><br/>
  84.     </body>
  85. </html>
  86. <?php include("footer.php"); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement