63 lines
1.8 KiB
PHP
63 lines
1.8 KiB
PHP
|
|
<?php
|
|
include "../indexes/ConnectDB.php";
|
|
|
|
// Start the session
|
|
session_start();
|
|
|
|
//get posted messages
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$user = $_POST["user"];
|
|
$pwd = $_POST["pwd"];
|
|
$user_type = $_POST["user_type"];
|
|
//select from db
|
|
$sql = "SELECT * FROM $user_type WHERE name = '$user' AND pwd = '$pwd' ";
|
|
|
|
// get the result from the query
|
|
$result = mysqli_query($conn, $sql);
|
|
|
|
// if the query returns some record, that means username and password are in the DB.
|
|
if(mysqli_num_rows($result)>0){
|
|
$_SESSION['loggedin'] = true;
|
|
$_SESSION['username'] = $user;
|
|
$_SESSION['user_type'] = $user_type;
|
|
|
|
//redirect to interface
|
|
echo "<script type='text/javascript'>
|
|
window.location.href = './interfaces/login_success.php';
|
|
</script>";
|
|
}
|
|
else{
|
|
echo "<script type='text/javascript'>
|
|
window.location.href = './interfaces/login_failed.php';
|
|
</script>";
|
|
}
|
|
}
|
|
|
|
// Check if the user is already logged in
|
|
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
|
|
//check usertype and redirct to user page
|
|
if(isset($_SESSION['user_type']) && $_SESSION['user_type'] === 'buyer'){
|
|
echo "<script type='text/javascript'>
|
|
window.location.href = './interfaces/login_buyer.php';
|
|
</script>";
|
|
}
|
|
if(isset($_SESSION['user_type']) && $_SESSION['user_type'] === 'seller'){
|
|
echo "<script type='text/javascript'>
|
|
window.location.href = './interfaces/login_seller.php';
|
|
</script>";
|
|
}
|
|
if(isset($_SESSION['user_type']) && $_SESSION['user_type'] === 'admin'){
|
|
echo "<script type='text/javascript'>
|
|
window.location.href = './interfaces/login_admin.php';
|
|
</script>";
|
|
}
|
|
}
|
|
|
|
else {
|
|
echo "<script type='text/javascript'>
|
|
window.top.location.href = './login.html';
|
|
</script>";
|
|
}
|
|
|
|
?>
|