Skip to content

Instantly share code, notes, and snippets.

@schlomo schlomo/login.php
Last active Aug 29, 2015

Embed
What would you like to do?
PHP Basic Auth Gateway. Requests basic auth (password is reversed username) and redirects to URL passed as query string
<?php
$username = 1;
$revpwd = 0;
if (isset($_SERVER['PHP_AUTH_USER']) and isset($_SERVER['PHP_AUTH_PW'])) {
$username = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];
$revpwd = strrev($password);
}
if ($username == $revpwd) {
if (isset($_SERVER['QUERY_STRING'])) {
header("Location: " . $_SERVER['QUERY_STRING']);
}
else {
echo "<p>Hallo {$_SERVER['PHP_AUTH_USER']}.</p>";
echo "<p>Set redirect target in query string, e.g. append <code>?http://schapiro.org</code> to the URL.</p>";
}
}
else {
header('WWW-Authenticate: Basic realm="Login Test"');
header('HTTP/1.0 401 Unauthorized');
echo '<p>Password is reversed Username</p>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.