我有一個(gè)帶有一些普通方法的類 User 和一個(gè)傳遞 $pdo 對(duì)象的構(gòu)造函數(shù)。還有一個(gè)名為isLogged()的方法,它只檢查是否設(shè)置了必要的會(huì)話變量。但是,如果我只想檢查用戶是否已登錄,而不建立數(shù)據(jù)庫連接怎么辦?// I need to check if user is logged here but it requires including db.phprequire 'includes/db.php';$user = new User($pdo);if (!$user->isLogged()) { header('Location: index.php'); exit;}if ($_SERVER['REQUEST_METHOD'] === 'POST') { // POST validation // ... // That is the place where DB connection should be made}
如何在不建立數(shù)據(jù)庫連接的情況下檢查用戶是否登錄(用戶類)
慕碼人2483693
2023-03-04 14:14:13