Webbserverprogrammering 1

Show sourcecode

The following files exists in this folder. Click to view.

ramverket/exercises/cookie-session/

ovn_cookie-session1.php
ovn_cookie-session2.php
ovn_cookie-session3.php
ovn_cookie-session4.php
ovn_cookie-session5.php

ovn_cookie-session3.php

43 lines UTF-8 Windows (CRLF)
<?php
  
// Title: Cookie-Session 3
  
error_reporting(-1); // Report all type of errors
  
ini_set('display_errors'1); // Display all errors
  
ini_set('output_buffering'0); // Do not buffer outputs, write directly
?>

<?php 
  session_start
();

  if (isset(
$_POST['password'])) {
    
$_SESSION['password'] = $_POST['password'];
  }

  if (isset(
$_POST['logout'])) {
    
session_unset();
    
session_destroy();
  }
?>

<!DOCTYPE html>
<html lang="sv">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Cookie-Session 3</title>
</head>
<body>
  <?php if (isset($_SESSION['password']) && ($_SESSION['password']) === 'jail') { ?>
    <?php echo 'Hemligheter'?>
    <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="POST">
      <input type="hidden" name="logout" value="logout">
      <button type="submit" value="Logga ut">Logga ut</button>
    </form>
  <?php } else { ?>
    <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="POST">
      <input type="password" name="password" placeholder="Lösenord">
      <button type="submit" value="Skicka">Skicka</button>
    </form>
  <?php }
  
?>
</body>
</html>