<?PHP
if(!isset($_SESSION["username"]) && !isset($_SESSION["password"])){
echo "Доступ закрыт!";exit();
}

$iduser = (isset($_SESSION["iduser"]) && preg_match("|^[\d]{1,11}$|", trim($_SESSION["iduser"]))) ? intval(trim($_SESSION["iduser"])) : false;

$adm = mysql_result(mysql_query("SELECT `user_status` FROM `b_users` WHERE `id`='$iduser'"),0,0);  
if ($adm != "moder"){
echo "Доступ закрыт!";exit();
}

$blockip = mysql_result(mysql_query("SELECT `blockip` FROM `tb_site` WHERE `id`='1'"),0,0);

$lastip = getRealIP();
$v = substr($lastip,0,strlen($blockip));
if($v != $blockip){
echo "Доступ закрыт!";exit();
}

$rs=mysql_query("SELECT `ctrlword` FROM `tb_site` WHERE `id`='1'");
$rs=mysql_fetch_array($rs);
$ctrlword = $rs["ctrlword"];

if($ctrlword != "" AND $_SESSION["ctrlwordaccess"] != '1'){
if($_POST["ctrlword"] != ""){
$ctrlwordver = $_POST["ctrlword"];
$ctrlwordver = md5($ctrlwordver);

if($ctrlwordver != $ctrlword){
echo "<br><br><br><br><br><center><font color=#ff0000><b>Неправильно введено контрольное слово!</b></font></center>";
exit();
}else{
$_SESSION["ctrlwordaccess"] = '1';
}
}else{
?>
<br><br><br><br><br><center>
<form action="" method="post">
<b>Введите контрольную фразу для получения доступа к админке:</b><br>
<input type="text" value="" size="30" maxlength="20" name="ctrlword"><br><br>
<input type="submit" value="Вход">
</form></center>
<?
exit();
}
}
?>