Skip to content

Instantly share code, notes, and snippets.

@artoodetoo
Created April 24, 2014 06:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artoodetoo/11243514 to your computer and use it in GitHub Desktop.
Save artoodetoo/11243514 to your computer and use it in GitHub Desktop.
Basic Auth with loop after Cancel and Logout option
<?php
$login = 'user';
$pass = 'userpass';
if (empty($_SERVER['PHP_AUTH_USER']) ||
$_SERVER['PHP_AUTH_USER'] !== $login ||
$_SERVER['PHP_AUTH_PW'] !== $pass) {
header('WWW-Authenticate: Basic realm="Enter user/userpass as login and password"');
header('HTTP/1.0 401 Unauthorized');
?>
<!doctype html>
<html>
<head>
<meta http-equiv="refresh" content="0;url=http://<?= $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] ?>">
</head>
<body>
You MUST log in. Redirecting&hellip;
</body>
</html>
<?php
exit;
}
?>
<!doctype html>
<html>
<head>
</head>
<body>
<h1>Secured content</h1>
<a href="http://log:out@<?= $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] ?>">Log out</a>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment