Certain user redirect themselves to a particular page

Asked

Viewed 35 times

0

Good evening I have a doubt I’m trying to make a database user in this case is the adm that if I log in with the adm i go to a specific page, in this case a backoffice; only that I’m not getting.

<?php
session_start(); // Starting Session
$error = ''; // Variable To Store Error Message
if (isset($_POST['submit'])) {
if (empty($_POST['username']) || empty($_POST['password'])) {
$error = "Username or Password is invalid";
}
else{
// Define $username and $password
$username = $_POST['username'];
$password = $_POST['password'];

// mysqli_connect() function opens a new connection to the MySQL server.
$conn = mysqli_connect("localhost", "root", "", "company");
// SQL query to fetch information of registerd users and finds user match.
$query = "SELECT username, password from login where username=? AND password=? LIMIT 1";
// To protect MySQL injection for Security purpose
$stmt = $conn->prepare($query);
$stmt->bind_param("ss", $username, $password);
$stmt->execute();
$stmt->bind_result($username, $password);
$stmt->store_result();

if($stmt->fetch()) //fetching the contents of the row {
$_SESSION['login_user'] = $username; // Initializing Session
header("location: profile.php"); // Redirecting To Profile Page
}
mysqli_close($conn); // Closing Connection
}

?>
  • Hello Roman. Do not place code picture or your question will be deleted. Edit and delete the image and place the typed code. To format it select all and type Ctrl+K

1 answer

0


I don’t know if he’ll see you, but in a simple way he can:

if ($info['status'] == '1') { // verifica o valor de status no banco de dados
    //redireciona o admin para a dashboard administrativa
    header("Location: admin.php");
} else {
    //redireciona o usuário comum ao site
    header("Location: main.php");  
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.