A
A
alexei_20022021-05-02 01:06:51
PHP
alexei_2002, 2021-05-02 01:06:51

Authorization interface / Working with mysql?

I'm trying to authorize using mysql according to the example https://htmlweb.ru/php/example/avtorizacija2.php
I ran into a problem... After registration and authorization, according to the condition, it gives an error "Enable cookies".
Cookies are enabled. I believe that the hash is not entered into the table, but I could be wrong
PS PHP I don’t know well, but now I have to parse it for a college project ...
I would be grateful for your help

<?
// Скрипт проверки

//Здесь переменные для подключения к БД
require_once 'connection.php';

// Соединямся с БД
$link = mysqli_connect($host, $user, $password, $database) 
    or die("Ошибка подключения к БД! " . mysqli_error($link));

if (isset($_COOKIE['id']) and isset($_COOKIE['hash']))
{
    $query = mysqli_query($link, "SELECT *,INET_NTOA(user_ip) AS user_ip FROM users WHERE user_id = '".intval($_COOKIE['id'])."' LIMIT 1");
    $userdata = mysqli_fetch_assoc($query);

    if(($userdata['user_hash'] !== $_COOKIE['hash']) or ($userdata['user_id'] !== $_COOKIE['id'])
 or (($userdata['user_ip'] !== $_SERVER['REMOTE_ADDR'])  and ($userdata['user_ip'] !== "0")))
    {
        setcookie("id", "", time() - 3600*24*30*12, "/");
        setcookie("hash", "", time() - 3600*24*30*12, "/", null, null, true); // httponly !!!
        print "Хм, что-то не получилось";
    }
    else
    {
        print "Привет, ".$userdata['user_login'].". Всё работает!";
    }
}
else
{
    print "Включите куки";
}
?>

Table from MYSQL
608dcf3278894380570342.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question