PHP会话,未定义常量


PHP sessions, undefined constant

<?php 
session_start(); 

if (!isset($_SESSION[auth])) {
    header('Location: login.php');
}
else {
    $auth = $_SESSION[auth];
}
if ($auth == 1) {
    echo "User access has been granted!";
}
else {
    header('Location: login.php');
}
?>

我得到:注意:使用未定义的常量auth -假设'auth'。我不明白这个错误,我正在检查以确保设置$_SESSION[auth]。在网上找不到好的答案。

auth需要单引号

$_SESSION['auth']

用- $auth = $_SESSION['auth'];代替$auth = $_SESSION[auth];