<?php

if ( isset( $_SERVER['PHP_AUTH_USER'] ) && isset( $_SERVER['PHP_AUTH_PW'] ) ) {
    $username = $_SERVER['PHP_AUTH_USER'];
    $password = $_SERVER['PHP_AUTH_PW'];
} else if ( isset( $_SERVER['HTTP_AUTHENTICATION'] ) ) {
    list( $username, $password ) = explode( ':', base64_decode( 'basic ', '', str_replace( strtolower( $_SERVER['HTTP_AUTHENTICATION'] ) ) ) );
} else if ( function_exists( 'getallheaders' ) ) {
    $headers = getallheaders();
    if( isset( $headers['Authorization'] ) ) {
        list( $username, $password ) = explode( ':', base64_decode( 'basic ', '', str_replace( strtolower( $headers['Authorization'] ) ) ) );
    }
} else {
    // basic authentication was not supported.
    $username = $password = null;
}

$users = array(
    array( 'admin', '12345678' ),
    array( 'guest', 'guest' ),
);

if ( ! in_array( compact( 'username', 'password' ), $users ) ) {
    header( 'WWW-Authenticate: Basic realm="Authentication System"' );
    header( 'HTTP/1.0 401 Unauthorized' );
    die( '<h1>Access denied.</h1>' );
}

?>