<?php
include("bloks/bd.php");
if (!isset($_SERVER['PHP_AUTH_USER']))
{
Header ("WWW-Authenticate: Basic realm=\"Admin Page\"");
Header ("HTTP/1.0 401 Unauthorized");
exit();
}
else {
if (!get_magic_quotes_gpc()) {
$_SERVER['PHP_AUTH_USER'] = mysql_escape_string($_SERVER['PHP_AUTH_USER']);
$_SERVER['PHP_AUTH_PW'] = mysql_escape_string($_SERVER['PHP_AUTH_PW']);
}
$query = "SELECT pass FROM userlist WHERE user='".$_SERVER['PHP_AUTH_USER']."'";
$lst = @mysql_query($query);
if (!$lst)
{
Header ("WWW-Authenticate: Basic realm=\"Admin Page\"");
Header ("HTTP/1.0 401 Unauthorized");
exit();
}
if (mysql_num_rows($lst) == 0)
{
Header ("WWW-Authenticate: Basic realm=\"Admin Page\"");
Header ("HTTP/1.0 401 Unauthorized");
exit();
}
$pass = @mysql_fetch_array($lst);
if ($_SERVER['PHP_AUTH_PW']!= $pass['pass'])
{
Header ("WWW-Authenticate: Basic realm=\"Admin Page\"");
Header ("HTTP/1.0 401 Unauthorized");
exit();
}
}
?>
и таблица в mysql
Структура таблицы `userlist`
CREATE TABLE `userlist` (
`id` int(3) NOT NULL auto_increment,
`user` varchar(50) NOT NULL default '',
`pass` varchar(50) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=2 ;
#
# Дамп данных таблицы `userlist`
#
INSERT INTO `userlist` VALUES (1, 'phpuser', 'php');
В начало защищаемого файла устанавливаю
<?php include ("lock.php");?>
при обращении выскакивает ошибка
Warning: Cannot modify header information - headers already sent by (output started at z:\home\localhost\www\kemt\admin\bloks\bd.php:4) in z:\home\localhost\www\kemt\admin\lock.php on line 7
Warning: Cannot modify header information - headers already sent by (output started at z:\home\localhost\www\kemt\admin\bloks\bd.php:4) in z:\home\localhost\www\kemt\admin\lock.php on line 8
тут не просто так дохуя разных подсветок синтаксиса….