Skip to content

Instantly share code, notes, and snippets.

@agentsib
Created July 23, 2019 10:02
Show Gist options
  • Save agentsib/609036e0e3c9a3b957dc1f4db9e461e4 to your computer and use it in GitHub Desktop.
Save agentsib/609036e0e3c9a3b957dc1f4db9e461e4 to your computer and use it in GitHub Desktop.
Basic Auth PHP
<?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