如何解决未定义的索引,虽然我已经在头文件的顶部开始会话,它显示未定义的索引?
显示以下错误:-注意:未定义的索引:signed_in在C:'xampp'htdocs'web_forum'header.php第26行
第26行
if($_SESSION['signed_in'])
header。php
<?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">
footer。php
</div><!--content-->
</div><!--wrapper-->
<div id="footer">Created for webinar by Swastik Shrestha.</div>
</body>
</html>
您应该这样使用isset()
方法:
if(isset($_SESSION['signed_in'])) { ... }
希望这对你有帮助!