如何解决未定义的索引虽然我已经在头文件的顶部启动了会话,但它显示了未定义的索引?
显示以下错误: - 注意:未定义的索引:第26行的C:\ xampp \ htdocs \ web_forum \ header.php中的signed_in
第26行
if($_SESSION['signed_in'])
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="description" content="A short description."/>
<meta name="keywords" content="put, keywords, here"/>
<title>Webinar</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<h1>Webinar</h1>
<div id="wrapper">
<div id="menu">
<a class="item" href="index.php">Home</a> -
<a class="item" href="create_topic.php">Create a topic</a> -
<a class="item" href="create_cat.php">Create a category</a>
<div id="userbar">
<?php
if($_SESSION['signed_in'])
{
echo 'Hello <b>' . htmlentities($_SESSION['user_name']) . '</b>. Not you? <a class="item" href="signout.php">Sign out</a>';
}
else
{
echo '<a class="item" href="signin.php">Sign in</a> or <a class="item" href="signup.php">create an account</a>';
}
?>
</div>
</div>
<div id="content">
</div><!--content-->
</div><!--wrapper-->
<div id="footer">Created for webinar by Swastik Shrestha.</div>
</body>
</html>
答案 0 :(得分:1)
您应该使用isset()
这样的方法:
if(isset($_SESSION['signed_in'])) { ... }
希望这有帮助!