問題が発生しています.2 つのログイン フォームがあり、同じページを使用しますが、使用しているアカウントの種類によって機能が異なります。
ともかく..
このコードを見ると、非常に明確に理解できます。
<?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'] は未定義です。
どんな助けでも大歓迎です、ありがとう。