<?
session_start();

$username = "admin";
$password = "pass";

if (isset($_GET['logout'])) {
  $_SESSION = array();
  session_destroy();
}
if (isset($_POST['submit'])) {
  if (isset($_POST['user']) && $_POST['user'] == $username && isset($_POST['pass']) && $_POST['pass'] == $password) {
    $_SESSION['user'] = $username;
  }
}
if (!isset($_SESSION['user'])) {
  echo "<form method=post action=?>
  Username: <input type=textbox name=user><BR>
  Password: <input type=textbox name=pass><BR>
  <input type=Submit name=submit></form>";
}
if (isset($_SESSION['user'])) {
  echo "Hello <B>" . $_SESSION['user'] . "</B>";
}
?>
Published in: PHP
Download

Related snippets