-1

On my index.php page I have this:

session_start();

if($_SESSION['logged_in']==true) {
   header("Location:home.php");
} else {
   header("Location:login.php");
}

On my login page, whenever the user correctly inputs the username and password I wrote this:

$_SESSION['username']=$username;

I used this as a reference to the future pages. But on my home.php, no matter what I do it keeps giving me this error:

 Undefined variable: _SESSION in C:\xampp\htdocs\website\home.php on line 8

The line 8 is:

$user= $_SESSION['username'];
Dranreb
  • 97
  • 2
  • 9

2 Answers2

0

In home.php you must call session_start(); at the very beginning of the file too.

gmc
  • 3,910
  • 2
  • 31
  • 44
  • Thanks! I thought that you will only have to call a `session_start()` only once per site. That's why I only placed it on the `index.php` – Dranreb Mar 28 '17 at 23:19
0

You need to call session_start() on each php file that is loaded.

Since php works by parsing each php file individually, you will have to have this at every page you have.

Robert I
  • 1,509
  • 2
  • 11
  • 18