0

I am trying to create a small forum as an assignment. I have a header.php file which will change some text depending on whether the user is logged in or not but it is giving me the following error

Notice: Undefined variable: _SESSION in C:\USBWEBSERVER\root\Final Project\header.php on line 21

The lines in question are

    <?php
    echo '<div id="userbar">';
         if($_SESSION['signed_in'])
              {
                echo 'Hello' . $_SESSION['user_name'] . '. Not you? <a href="signout.php">Sign out</a>';
              }
              else
              {
                echo '<a href="signin.php">Sign in</a> or <a href="sign up">create an account</a>.';
              }
    echo '</div>'
    ?>

How do I solve this?

https://i.stack.imgur.com/C6wEJ.png picture of the error even after signing in.

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119

1 Answers1

0

Put session_start() at the top of PHP script.

<?php

session_start();
// your script goes here
pavel
  • 26,538
  • 10
  • 45
  • 61