Created
April 24, 2014 06:20
-
-
Save artoodetoo/11243514 to your computer and use it in GitHub Desktop.
Basic Auth with loop after Cancel and Logout option
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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… | |
</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