Skip to content

Instantly share code, notes, and snippets.

@andypotanin
Created October 29, 2014 03:28
Show Gist options
  • Select an option

  • Save andypotanin/b664345a586ced09964a to your computer and use it in GitHub Desktop.

Select an option

Save andypotanin/b664345a586ced09964a to your computer and use it in GitHub Desktop.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*)$ /secure.php?path=$1 [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>
<?php
if( !isset( $_SERVER[ 'HTTP_AUTHORIZATION'] ) && isset( $_SERVER[ 'REDIRECT_HTTP_AUTHORIZATION' ] ) ) {
$_SERVER[ 'HTTP_AUTHORIZATION' ] = $_SERVER[ 'REDIRECT_HTTP_AUTHORIZATION' ];
}
list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
header( 'cache-control: no-cache' );
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'Text to send if user hits Cancel button';
exit;
} else {
echo "<p>Hello, </p>".$_SERVER['PHP_AUTH_USER'];
echo "<p>You entered as your password: </p>".$_SERVER['PHP_AUTH_PW'];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment