$ _SESSION ['']无法使用PHP

时间:2015-03-31 14:44:04

标签: php session login location session-variables

我目前正在使用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 [&#39; authuser&#39;] = 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/');

1 个答案:

答案 0 :(得分:3)

尝试改变:

$_SESSION['authuser'] == 1;

使用

$_SESSION['authuser'] = 1;

因为这样你就做了作业!