Php 如何获取登录用户的id
我试图让它从数据库中提取与登录用户匹配的id。这样,只有管理员才能使用该页面Php 如何获取登录用户的id,php,Php,我试图让它从数据库中提取与登录用户匹配的id。这样,只有管理员才能使用该页面 <?php require_once('../database.php'); // Get users $query = 'SELECT * FROM login'; $statement = $db->prepare($query); $statement->execute(); $login = $statement->fetchAll();
<?php
require_once('../database.php');
// Get users
$query = 'SELECT *
FROM login';
$statement = $db->prepare($query);
$statement->execute();
$login = $statement->fetchAll();
$statement->closeCursor();
session_start();
if (isset($_SESSION['authorized']) && $_SESSION['authorized'] === TRUE) {
//If the user is authorized
echo "";
} else {
// User is not authorized!
header('Location: ../login_page.php');
exit();
}
if($id == 2){
//If the user is authorized
echo "";
} else {
// User is not authorized!
header('Location: ../login_page.php');
exit();
}
?>
问题是…?它没有像我希望的那样提取id。因为我登录的帐户应该是id==2,但它不起作用。我想你正在寻找这样一个非常模糊的东西。如何初始化$id
?我看到您正在获取所有用户,但您是基于什么信息获取id的?此外,如果您需要使用id,那么将其放在会话中也是明智的。