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?

http://i.imgur.com/s10ktiP.png picture of the error even after signing in.

Jay Blanchard
  • 33,530
  • 16
  • 73
  • 113

1 Answers1

0

Put session_start() at the top of PHP script.

<?php

session_start();
// your script goes here
pavel
  • 25,361
  • 10
  • 41
  • 58