-4

This is my code.

<?php

include("include/dbcon.php");
if($_SESSION['admin']){      //this is where the error starts
    header("location:admin/");
}else if($_SESSION['users']){   //and here also
    header('location:employee/');
}else{
    header:('location:/deped2/');
}
?>

Please help me with this code

Adelson Araújo
  • 332
  • 1
  • 5
  • 17
  • chk session, did u start your session or not – devpro Jan 20 '17 at 14:45
  • In addition to the current answer which will solve your issue, I would like to suggest using `exit;` after each `header('Location: ...')`. – Peter Jan 20 '17 at 14:50

1 Answers1

3

You are not checking whether the Session Index is set or not. It would be better if you first start the session then check if the variables are present or not.

Try this and adding exit; after each header. Otherwise, your code might want to continue to execute.

<?php

if(!isset($_SESSION)){
session_start();
}
include("include/dbcon.php");
if(isset($_SESSION['admin'])){      //this is where the error starts
    header("location:admin/");
    exit;
}else if(isset($_SESSION['users'])){   //and here also
    header('location:employee/');
    exit;
}else{
    header:('location:/deped2/');
    exit;
}

?>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Abhishek
  • 1,008
  • 1
  • 16
  • 39