Код: Выделить всё
<?php
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
if (!isset($_SERVER['PHP_AUTH_USER']) ||
!($_SERVER['PHP_AUTH_USER']=='zloy') ||
!($_SERVER['PHP_AUTH_PW']=='zloypass'))
{
header("WWW-Authenticate: Basic realm=\"Adm Zone\"");
header("HTTP/1.0 401 Unauthorized");
echo "Access denied";
exit;
}
?>
Код: Выделить всё
$host = 'exemple.com'; //ну тут понятно, сайт, где находиться защищенная зона
$path = '/admin'; //путь до нужной папки
$logins = 'logins.txt'; //файл с логинами
$passwords = 'passwords.txt'; //файл с паролями
$cookie = ''; //куки, если нужны
$referer = 'http://exemple.com/index.html'; //с какой страницы перешли, если нужно
Код: Выделить всё
function http_auth($host, $path, $login, $password)
{
global $cookie, $referer;
$header = 'GET '.$path.' HTTP/1.1'."\r\n".
'Host: '.$host."\r\n".
'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2 (.NET CLR 3.5.30729)'."\r\n".
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'."\r\n".
'Accept-Language: ru,en-us;q=0.7,en;q=0.3'."\r\n".
'Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7'."\r\n".
'Keep-Alive: 115'."\r\n".
'Connection: keep-alive'."\r\n";
if($referer) $header .= 'Referer: '.$referer."\r\n";
if($cookie) $header .= 'Cookie: '.$cookie."\r\n";
$header .= 'Authorization: Basic '.base64_encode($login.':'.$password)."\r\n";
$header .= 'Cache-Control: max-age=0'."\r\n"."\r\n";
$f = fsockopen($host, 80);
fputs($f, $header);
$out = '';
while(!feof($f))
$out .= fread($f, 128);
return $out;
}