DavidWel

index.php

Jan 21st, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.06 KB | None | 0 0
  1. <?php
  2.   session_start();
  3.  
  4.   if (!isset($_SESSION['username'])) {
  5.     $_SESSION['msg'] = "You must log in first";
  6.     header('location: login.php');
  7.   }
  8.   if (isset($_GET['logout'])) {
  9.     session_destroy();
  10.     unset($_SESSION['username']);
  11.     header("location: login.php");
  12.   }
  13. ?>
  14. <!DOCTYPE html>
  15. <html>
  16. <head>
  17.     <title>Home</title>
  18.     <link rel="stylesheet" type="text/css" href="style.css">
  19. </head>
  20. <body>
  21.  
  22. <div class="header">
  23.     <h2>Home Page</h2>
  24. </div>
  25. <div class="content">
  26.     <!-- notification message -->
  27.     <?php if (isset($_SESSION['success'])) : ?>
  28.       <div class="error success" >
  29.         <h3>
  30.           <?php
  31.             echo $_SESSION['success'];
  32.             unset($_SESSION['success']);
  33.           ?>
  34.         </h3>
  35.       </div>
  36.     <?php endif ?>
  37.  
  38.     <!-- logged in user information -->
  39.     <?php  if (isset($_SESSION['username'])) : ?>
  40.         <p>Welcome <strong><?php echo $_SESSION['username']; ?></strong></p>
  41.         <p> <a href="index.php?logout='1'" style="color: red;">logout</a> </p>
  42.     <?php endif ?>
  43. </div>
  44.        
  45. </body>
  46. </html>
Advertisement
Add Comment
Please, Sign In to add comment