我有一個帶有一些普通方法的類 User 和一個傳遞 $pdo 對象的構造函數。還有一個名為isLogged()的方法,它只檢查是否設置了必要的會話變量。但是,如果我只想檢查用戶是否已登錄,而不建立數據庫連接怎么辦?// 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}
如何在不建立數據庫連接的情況下檢查用戶是否登錄(用戶類)
慕碼人2483693
2023-03-04 14:14:13