Hello!

Tell me, please, when using the authorization module in chrome, an error occurs: “Cyclic redirection is detected on the page,” everything works fine in the opera, the explorer hangs at all. Block Code:

<? $user_status = '0'; // обнуляем статус пользователя, 0 - пользователь не авторизован // запрещаем прямой вызов файла if ($_SERVER['HTTP_REFERER'] == NULL) { header ('Location: /admin/'); } if (isset ($_COOKIE['Login']) || isset ($_COOKIE['Password'])) { $_COOKIE['Login'] = htmlspecialchars ($_COOKIE['Login']); $_COOKIE['Password'] = htmlspecialchars ($_COOKIE['Password']); } // читаем куки и смотрим, есть ли в базе пользователь с таким паролем, // и проверяем были ли нажаты кнопки вход или выход if (isset ($_COOKIE['Login']) && isset ($_COOKIE['Password']) && empty ($_POST['auth']) && empty ($_GET['exit'])) { // запрос $sql = mysql_query ("SELECT * FROM `" . DB_PREFIX . "_users` WHERE `login` = '" . $_COOKIE['Login'] . "' && `password` = '" . $_COOKIE['Password'] . "'"); // если есть совпадение, авторизуем пользователя if (mysql_num_rows ($sql) > 0) { // собираем все данные о пользователе в массив $userinfo = mysql_fetch_array ($sql); // устанавливаем куки SetCookie ("Login", $userinfo['login']); SetCookie ("Password", $userinfo['password']); $user_status = '1'; // статус пользователя, 1 - авторизован админ } } // если была нажата кнопка из формы авторизации if ($_POST['auth']) { // ищем совпадение пары логин-пароль в таблице $auth = mysql_query ("SELECT * FROM `" . DB_PREFIX . "_users` WHERE `login` = '" . $_POST['login'] . "' && `password` = '" . $_POST ['pass'] . "'"); // если есть совпадение, авторизуем пользователя if (mysql_num_rows($auth) > '0'){ // собираем все данные о пользователе в массив $userinfo = mysql_fetch_array ($auth); // устанавливаем куки SetCookie ('Login', $_POST['login']); SetCookie ('Password', $_POST['pass']); $user_status = '1'; // статус пользователя, 1 - авторизован админ } else { // если если пара логин-пароль не совпала, выводим сообщение об ошибке echo "Такой пользователь не существует или пароль не верный."; } } // если нажата кнопка выход if ($_GET['exit']) { // удаляем куки SetCookie ('Login', $_POST['login']); SetCookie ('Password', $_POST['pass']); } // если статус пользователя не изменился, выводим форму авторизации if ($user_status == '0') { include $_SERVER['DOCUMENT_ROOT'] . '/admin/inc/header.php'; // шапка админки ?> <!-- форма авторизации --> <div style="position:absolute;width:260px;left:50%;top:50%; margin-left:-150px;margin-top:-100px;background:#777;color:#eee; border:solid 1px black;padding:10px; font-family:Tahoma,Arial,FreeSans,Garuda,Utkal,sans-serif;overflow:auto"> <form method="post" action="index.php"> Логин:<br> <input type="text" name="login" style="width:250px"> <br><br> Пароль:<br> <input type="password" name="pass" style="width:250px"> <br><br> <input type="submit" name="auth" value="Войти"> </form> </div> <? } ?> 
  • @Mariya, To format the code, select it with the mouse and click on the button 101010 of the editor. - Nicolas Chabanovsky
  • @Mariya, what is stored in the admin / inc / header.php file? - V_Tjuryakin
  • In admin / inc / header.php? trace code. <? if ($ user_status == '0') {header ('Location: / admin /'); // deny direct access to the file}?>> <! DOCTYPE HTML PUBLIC "- // W3C // DTD HTML 4.01 // EN" " w3.org/TR/html4/strict.dtd "> <html> <head> < title> <? if (@ $ admin_title) {echo $ admin_title. "-";}?> Site Control Panel </ title> <meta http-equiv = "Content-Type" content = "text / html; charset = utf-8"> <link rel = "stylesheet" type = "text / css "href =" / admin / style.css "> <? if ($ _GET ['event'] == 'add' || $ _GET ['event'] == 'edit') {?> <? }?> </ head> - masha2
  • 3
    Warning: You are easily hacked by substituting a SQL injection into a cookie. - Sergiks
  • @sergiks, I think that this person writes for himself - it cannot be otherwise, otherwise it is epic fail. - V_Tjuryakin

1 answer 1

Error here. There is always a referrer.

 if ($_SERVER['HTTP_REFERER'] == NULL) { header ('Location: /admin/'); }