Skip to content

Instantly share code, notes, and snippets.

@schlomo
Last active August 29, 2015 14:01
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 schlomo/17579ede67fc16311ee0 to your computer and use it in GitHub Desktop.
Save schlomo/17579ede67fc16311ee0 to your computer and use it in GitHub Desktop.
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