Created
July 23, 2019 10:02
-
-
Save agentsib/609036e0e3c9a3b957dc1f4db9e461e4 to your computer and use it in GitHub Desktop.
Basic Auth PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// логин и пароль | |
$login = "admin"; | |
$password = "pass"; | |
$authPass = false; | |
if(isset($_SERVER['PHP_AUTH_USER']) && ($_SERVER['PHP_AUTH_PW'] == $password) && (strtolower($_SERVER['PHP_AUTH_USER']) == $login)){ | |
$authPass = true; | |
} | |
if (!$authPass) { | |
header('WWW-Authenticate: Basic realm="Backend"'); | |
header('HTTP/1.0 401 Unauthorized'); | |
echo 'Authenticate required!'; // Если в интерактивном режиме пользователь нажмет escape. | |
exit(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment