S. Shrestha S. Shrestha - 9 months ago 60
PHP Question

How to solve undefine index?

How to solve undefined index although i have started session in the top of the header file it shows undefined index?

The following error was shown:-
Notice: Undefined index: signed_in in C:\xampp\htdocs\web_forum\header.php on line 26

line 26



<!DOCTYPE html>
<meta charset="utf-8"/>
<meta name="description" content="A short description."/>
<meta name="keywords" content="put, keywords, here"/>
<link rel="stylesheet" type="text/css" href="css/style.css">

<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">
echo 'Hello <b>' . htmlentities($_SESSION['user_name']) . '</b>. Not you? <a class="item" href="signout.php">Sign out</a>';
echo '<a class="item" href="signin.php">Sign in</a> or <a class="item" href="signup.php">create an account</a>';

<div id="content">




<div id="footer">Created for webinar by Swastik Shrestha.</div>


Answer Source

You should use isset() method like this:

if(isset($_SESSION['signed_in'])) { ... }

Hope this helps!