The 5th Annual China PHP Conference

Voting

Please answer this simple SPAM challenge: three minus one?
(Example: nine)

The Note You're Voting On

s dot i dot g at gmx dot com
7 years ago
<?php

// try to mimic cpanel logout style
// only diff is usr & pwd field is cleared when re-login
// tested with ff2 & ie8

session_start();

$username = "test";
$password = "test";

if(isset(
$_GET['logout']))
{
  unset(
$_SESSION["login"]);
  echo
"You have logout ... ";
  echo
"[<a href='" . $_SERVER['PHP_SELF'] . "'>Login</a>]";
  exit;
}

if (!isset(
$_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || !isset($_SESSION["login"]))
{
 
header("WWW-Authenticate: Basic realm=\"Test\"");
 
header("HTTP/1.0 401 Unauthorized");
 
$_SESSION["login"] = true;
  echo
"You are unauthorized ... ";
  echo
"[<a href='" . $_SERVER['PHP_SELF'] . "'>Login</a>]";
  exit;
}
else
{
  if(
$_SERVER['PHP_AUTH_USER'] == $username && $_SERVER['PHP_AUTH_PW'] == $password)
  {
    echo
"You have logged in ... ";
    echo
"[<a href='" . $_SERVER['PHP_SELF'] . "?logout'>Logout</a>]";
  }
  else
  {
    unset(
$_SESSION["login"]);
   
header("Location: " . $_SERVER['PHP_SELF']);
  }
}

// content here

?>

<< Back to user notes page

To Top