I have been trying a few ways to direct to admin page or user page but its always unsuccessful. Here is my login.php page. Can anyone help me on this? Is there anything i can add in the if($user) session? Thank you in advance!
<?php
session_start();
if (isset($_SESSION["user"])){
header("location: index.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
<title>WebAssetGO|Login</title>
<style>
body{
padding: 50px;
}
.container{
max-width: 600px;
margin: 0 auto;
padding: 50px;
box-shadow: 0px 7px 29px 8px rgba(100,100, 111, 0.2);
}
.form-group{
margin-bottom:30px;
}
</style>
</head>
<body>
<div class="container">
<?php
if (isset($_POST["login"])) {
$umatric = $_POST["umatric"];
$upass = $_POST["upass"];
require_once "database.php";
$sql = "SELECT * FROM users WHERE umatric ='$umatric'";
$result = mysqli_query($conn, $sql);
$user = mysqli_fetch_array($result, MYSQLI_ASSOC);
if ($user){
if (password_verify($upass, $user["upass"])){
session_start();
$_SESSION["user"] = "yes";
header ("location: index.php");
die();
} else{
echo "<div class='alert alert-danger'>Password does not match.</div>";
header("location: login.php");
}
}else{
echo "<div class='alert alert-danger'>Matric Number does not exist.</div>";
header("location: login.php");
}
}
?>
<form action="login.php" method="post">
<div class="form-group">
<input type="text" placeholder="Enter Matric Number:" name="umatric" class="form-control">
</div>
<div class="form-group">
<input type="password" placeholder="Enter Password:" name="upass" class="form-control">
</div>
<div class="form-btn">
<input type="submit" value="Login" name="login" class="btn btn-primary">
</div>
</form>
<div>
<p>Not yet registered?<a href="registration.php">Register Now</a></p>
</div>
</div>
</body>
</html>
Im expecting to be able to direct the user and admin to their own specific page.
New contributor
Darkvicos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.