Итак, у меня есть страница, которую я хочу защитить, поэтому сначала нужно войти в систему, прежде чем они смогут получить доступ к странице.
Итак, это страница, на которую вы перенаправляетесь при входе в систему (login.php)
<?php
// include database.php and object files
include_once '../config/database.php';
include_once '../objects/user.php';
// get database.php connection
$database = new Database();
$db = $database->getConnection();
// prepare user object
$user = new User($db);
// set ID property of user to be edited
$user->username = isset($_GET['username']) ? $_GET['username'] : die();
$user->password = base64_encode(isset($_GET['password']) ? $_GET['password'] : die());
// read the details of user to be edited
$stmt = $user->login();
if($stmt->rowCount() > 0){
// get retrieved row
$row = $stmt->fetch(PDO::FETCH_ASSOC);
// create array
$user_arr=array(
"status" => true,
"message" => "Successfully Login!",
"id" => $row['id'],
"username" => $row['username']
);
header( "refresh:3;url=home.php" );
}
else{
$user_arr=array(
"status" => false,
"message" => "Invalid Username or Password!",
);
}
// make it json format
print_r(json_encode($user_arr));
?>
Как вы можете видеть, если вы вошли в систему, вы будете перенаправлены на "home.php", который является страницей, которую я хочу защитить, поэтому вы не можете получить к ней прямой доступ, когда знаете URL.
Итак, мой вопрос: как мне это сделать?