Answer the question
In order to leave comments, you need to log in
Authorization via PHP / personal dashboard / how to redirect each user to different pages after login?
How can different users, for example, be sent to different pages through a login and password?
for example, I have 3 different html pages, each page with different content for different users.
I want to make it so that, for example, when a user logged in with the mail '[email protected]' i password '123456', he went to profile.html, when the user logged in with the mail '[email protected]' and the password ''654321', his redirected to profile_1.html the
source authorization code
<?php
session_start();
require_once 'connect.php';
$login = $_POST['login'];
$password = $_POST['password'];
$error_fields = [];
if ($login === '') {
$error_fields[] = 'login';
$error_fields[] = 'password';
}
if (!empty($error_fields)) {
$response = [
"status" => false,
"type" => 1,
"message" => "Check if fields are correct",
"fields" => $error_fields
];
echo json_encode($response);
die();
}
$password = md5($password);
$check_user = mysqli_query($connect, "SELECT * FROM `users` WHERE `login` = '$login' AND `password` = '$password'");
if (mysqli_num_rows($check_user) > 0) {
$user = mysqli_fetch_assoc($check_user);
$_SESSION['user'] = [
"id"
"avatar" => $user['avatar'],
"email" => $user['email']
];
$response = [
"status" => true
];
echo json_encode($response);
} else {
$response = [
"status" => false,
"message" => 'Invalid login or password'
];
echo json_encode($response);
}
?>
Thanks
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question