Answer the question
In order to leave comments, you need to log in
Protecting the admin panel on a php site?
Friends, advise ways to protect the admin panel. I will be glad if you throw off some relevant guides.
In the database, in the users table, there is a status column. I want only users with status 3,4,5 to have access to the admin section, but I don’t quite understand how to implement this.
Answer the question
In order to leave comments, you need to log in
If you take a simple solution to this - you need to write a request where you check the status of the user.
I will sign a simple example, for simplicity we do not take into account protection against injections, etc.
For example, you need to only allow access to users with status = 4, then it might look like this.
For example, a user logs in via the login form and submits their username and password. You check them and pull data from the database. On a live example, you still need to write a check to see if the data entered is correct at all and whether such a user exists. But nonetheless.
$r = mysqli_query($mysqli, "
SELECT * FROM `users`
WHERE `email` = '$email'
AND `password` = '$password'
");
$f = mysqli_fetch_array($r);
if($f['status'] == '4') { // Если в поле status для текущего юзера у нас значение 4
echo 'Разрешаем доступ, выполняем дальнешие действия по авторизации';
} else {
echo 'Пользователю с вашим статусом доступ запрещен';
}
Good afternoon.
If you don't understand, then don't reinvent the wheel.
Take any framework, all this is implemented there. Learn how it works, and only then proceed to implement your own solution.
Start with YII2 or Laravel frameworks . You can also study this material in parallel .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question