Such trouble, the login form is on every page of the site, if I log into my account from the main page (index.php), then the authorization works fine and on all pages I appear as authorized. If I entered the full description of the news, for example, (mysite.ru/category/php/write/1/), and entered the authorization data on this page, then only on it I appear as an authorized user. login and password. What is the problem? I attach the code, it is included on every page of the site.
session_start(); //Проверка на авторизацию if (isset($_COOKIE['l']) && isset($_COOKIE['i'])) { $id_user = $_COOKIE['i']; $login_user = $_COOKIE['l']; $ip_user = $_COOKIE['ip']; } //Авторизация if(isset($_REQUEST['ok'])) { //Получение данных из формы if($_SERVER['REQUEST_METHOD'] == 'POST') { $l_login = clearData($_POST['l_login']); $l_password = hash('sha1', mysql_real_escape_string(trim(strip_tags($_POST['l_password'])))); } //Запрос на получение данных пользователя $query_login = "SELECT * FROM users WHERE login='$l_login' ANDpassword = '$ l_password' "; $ query_answer = mysql_query ($ query_login); $ logIn = mysql_fetch_array ($ query_answer);
//Объявляем нужные переменные $browser = $_SERVER['HTTP_USER_AGENT']; $time = time(); $id_user = $logIn['id_user']; $pass_user = $logIn['password']; $login_user = $logIn['login']; $ip_user = getenv("REMOTE_ADDR"); if($l_login == $login_user AND $l_password == $pass_user) { setcookie('ip', md5($user_ip), time() +3600*24); setcookie('l', $login_user, time() +3600*24); setcookie('i', $id_user, time() +3600*24); $_SESSION['login'] = $login_user; $_SESSION['id'] = $id_user; mysql_query("INSERT INTO session (id_user,time,ip,browser) VALUE('$ id_user', '$ time', '$ ip_user', '$ browser') ");}
if($_POST['remember'] == 'on') { setcookie('ip', md5($user_ip), time() +3600*24*7); setcookie('l', $login_user, time() +3600*24*7); setcookie('i', $id_user, time() +3600*24*7); } echo "<html><head><meta http-equiv='Refresh' content='0;URL = / index.php '> </ head> </ html> ";}