Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define( 'HTTP_AUTH_REALM', '' ); // login üzenet
- define( 'HTTP_AUTH_USER', '' );
- define( 'HTTP_AUTH_PASSWORD', '' );
- define( 'PROTECTED_FILE_PATH', '' ); // html fájl útvonala
- class HTTPAuth {
- public $username;
- public $password;
- public $realm;
- public $user = array();
- public function __construct( $username, $password, $realm = '' ) {
- $this->username = $username;
- $this->password = $password;
- $this->realm = $realm;
- }
- public function authenticate() {
- if ( $_SERVER['PHP_AUTH_USER'] !== $this->username || $_SERVER['PHP_AUTH_PW'] !== $this->password ) {
- header( 'WWW-Authenticate: Basic realm="' . $this->realm . '"' );
- header( 'HTTP/1.0 401 Unauthorized' );
- return false;
- } else {
- $this->user['username'] = $_SERVER['PHP_AUTH_USER'];
- $this->user['password'] = $_SERVER['PHP_AUTH_PW'];
- return true;
- }
- }
- }
- $httpAuth = new HTTPAuth( HTTP_AUTH_USER, HTTP_AUTH_PASSWORD, HTTP_AUTH_REALM );
- if ( $httpAuth->authenticate() ) {
- include( PROTECTED_FILE_PATH );
- } else {
- echo 'Permission denied';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement