0

我遇到了问题。我有两个登录表单,它们将使用相同的页面,但根据您拥有的帐户类型,它会具有不同的功能。

反正..

看到这段代码你会很清楚的明白:

<?php
session_start();
if (isset($_SESSION['username']) or $_SESSION['username'] == true) {
?>
<html>
<head>
<title></title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>

<div id="container">

    <div id="content">

        <div class="user_logged">

        <h3>Welcome <h3 class="red"><?php echo $_SESSION['username'];?></h3></h3>
        <a href="profile.php">Profile</a><br/>
        <a href="logout.php">Logout</a><br/>
        <a href="collect.php">Collect/save new ads</a>

        </div>

    </div>

</div>

</body>
</html>
<?php
} elseif (isset($_SESSION['biz_username']) or $_SESSION['biz_username'] == true){
include 'dbc.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>

<div id="container">

    <div id="content">

        <div class="user_logged">

            <h3>Welcome <h3 class="red"><?php echo $_SESSION['biz_username'];?></h3></h3>
            <a href="profile.php">Profile</a><br/>
            <a href="logout.php">Logout</a><br/>
            <a href="collect.php">Create a new ad</a>

        </div>
        <div class="mid_con">
            <h3>New<h3 class="red">Ads</h3></h3>
        <?php
            $n_adsquery = $dbh->prepare("SELECT name, ad_offer, content, expiration_date FROM biz_ads ORDER BY id DESC  LIMIT 0,5");
            $n_adsquery->execute();
            while ($row = $n_adsquery->fetch(PDO::FETCH_NUM)) {
                $name = $row[1];
                $ad_offer = $row[2];
                $content = $row[3];
                $expiration_date = $row[4];
            }

            echo $name;
            echo $ad_offer;
            echo $content;
            echo $expiration_date;
        ?>
        </div>
    </div>

</div>

</body>
</html>


<?php
} else {
    header ('Location: index.php');
}

?>

当以“普通”用户身份登录时,没有错误或任何东西,它或多或少地工作完美。但是当通过另一个登录表单登录时,它说“$_SESSION['username'] 未定义,即使我在通过此表单登录时没有使用它。

任何帮助表示赞赏,谢谢。

4

1 回答 1

1

当您检查 $_SESSION['username'] = true 您是否调用 $_SESSION['username'] 时,我猜第一行的问题,所以错误消息说“$_SESSION['username'] is undefined”

为什么你使用它,只是用它来检查会话是否为真。

if (isset($_SESSION['username']))
于 2013-06-02T13:35:13.353 回答