我現在正在開發一個論壇軟件,目前爲止我的表現非常好,一切正常,但我無法讓它脫身,我不是真的很確定。未定義的索引:使用會話時的用戶名
我得到了一個未定義指數:用戶名每當我打電話
$_SESSION['username']
我在一個單獨的登錄文件啓動會話,但每當調用它得到這個錯誤,我只把它當沒有登錄的人,所以如果我登錄,它不顯示它,只有當我沒有登錄,我怎麼能擺脫它?
這裏是我的整個頁面代碼:
<?php
session_start();
include_once("connect.php");
$find = "SELECT id,name,description FROM forums";
$run_find = mysql_query("$find");
if ($_SESSION['username']) {
print "Welcome, " . $_SESSION['username']. "!<br/>";
}
while($is = mysql_fetch_assoc ($run_find))
{
$id = $is['id'];
$name = $is['name'];
$des = $is['description'];
print "<div style='width:500px;background-color:#FFCCFF;'>";
print "Forum : <a href='topics.php?t=$id'>". $name . "</a><br/>" .$des . "<br/><hr>";
print "</div>";
}
if (!$_SESSION['username']) {
echo "
<form action='loginnext.php' method='post'>
Username: <input type='text' name='username'><br/>
Password: <input type='password' name='password'><br/>
<input type='submit' name='submit' value='Login'><br/></form>";
}
if ($_SESSION['username']) {
echo "<a href='logout.php'>Logout</a>";
}
?>
哪條線(S)?此外,你可以嘗試'if(isset($ _ SESSION ['username']))' – RageD
嘿,謝謝,isset工作。 – Darren