未登錄時,您可以在瀏覽器中鍵入此頁面的URL,並且表單仍顯示。如果沒有登錄,我不希望HTML顯示 - 只是消息說必須登錄。我在其他頁面上使用相同的會話代碼,它的工作原理 - 但確實給出了'未定義索引'這是一個通知有點刺激。有任何想法嗎?PHP會話開始不起作用
<?php
session_start();
if ($_SESSION['first_name']&& $_SESSION['username'])
echo "Welcome ".$_SESSION['first_name']."<br><a href='login/logged_out.php'>log
out</a>";
else
die("You must be logged in. Click <a href='login/login_page.php'>here</a> to log
in.");
?>
<html>
<head>
</head>
<body>
<form id="1" class="rounded" action="test4.php" method="post"/>
<input type="submit" name="submit" class="button" value="5" />
<form id="2" class="rounded" action="test4.php" method="post"/>
<input type="submit" name="submit" class="button" value="6" />
<form id="3" class="rounded" action="test4.php" method="post"/>
<input type="submit" name="submit" class="button" value="7" />
<form id="4" class="rounded" action="test4.php" method="post"/>
<input type="submit" name="submit" class="button" value="8" />
<form id="5" class="rounded" action="test4.php" method="post"/>
<input type="submit" name="submit" class="button" value="9" />
<form id="6" class="rounded" action="test4.php" method="post"/>
<input type="submit" name="submit" class="button" value="10" />
</form>
</body>
</html>
你確定你已經登入嗎? 在調用session_write_close()之前,人們在處理會話時最常犯的錯誤之一是重定向。 – 2012-03-14 23:55:57
[PHP:「Notice:Undefined variable」和「Notice:Undefined index」]的可能重複(http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – animuson 2012-03-14 23:57:57