$_SESSION[''] 在 PHP 中不工作

$_SESSION[''] not working in PHP

我目前正在使用 MAMP,但是我也使用 GoDaddy(我的网络主机)进行了测试。

这是从 HTML 表单接收信息并设置 authuser 的页面。

<?php
    session_start();

    $_SESSION['username'] = $_POST['user'];
    $_SESSION['password'] = $_POST['pass'];
    $_SESSION['authuser'] = 0;
    //Check to see if login is good
    if (($_SESSION['username'] == 'Admin') and
        ($_SESSION['password'] == 'Password1')) {
    $_SESSION['authuser'] == 1;
        echo  "CORRECT";
        echo $_SESSION['authuser'];
    } else {
        echo "Sorry but you dont have permission to view this page!";
        echo $_SESSION['username'];
        echo $_SESSION['password'];
        echo $_SESSION['authuser'];
        exit();
    }
?>
<html>
    <head>
        <title>Find my Favorite Movie!</title>
    </head>
    <body>
        <?php
          $myFavorite = urlencode("The Life of Brian");
          echo "<a href= 'moviesite.php?favmovie=$myFavorite'>";
          echo "Click here to see information about my favorite movie!";
          echo "</a>";
        ?>
    </body>
</html>

由于用户名和密码确实匹配,此页面已加载,但当我进入下一页时,它说我无权查看该页面,因为我的 $_SESSION['authuser'] = 0。(即使我在用户名和密码正确时将其设置为 1,该值也没有改变。) 这是向我抛出错误的页面,以防它有所作为。

<?php
session_start();

if($_SESSION['authuser'] != 1) {
    echo "Sorry, but you don't have permission to view this page!";
    echo $_SESSION['username'];
    echo $_SESSION['password'];
    echo $_SESSION['authuser'];
    exit();
}
?>
<html>
    <head>
        <title>My Movie Site - <?php echo $_REQUEST['favmovie']; ?></title>
    </head>
    <body>
        <?php
            echo "Welcome to our site ";
            echo $_SESSION['username'];
            echo "<br>";
            echo "My Favorite Movie Is ";
            echo $_REQUEST['favmovie'];
            echo "<br>";
            $movierate = 5;
            echo "My movie rating for this movie is: ";
            echo $movierate;
        ?>
    </body>
</html>

我试过多次更改临时文件夹的路径,我也试过将它放在页面顶部的

ini_set('session.save_path', '/Users/Joseph/Desktop/PHPTEMP/');

尝试改变:

$_SESSION['authuser'] == 1;

$_SESSION['authuser'] = 1;

因为你用这种方式做作业!