I am trying to check whether a user is logged in or not on the index.php page. If user is not logged in I want to redirect the user to login.php page.
Below is error log:
> PHP Warning: Cannot modify header information - headers already sent
> by (output started at
> /home/consolem/public_html/megalibrary/index.php:2) in
> /home/consolem/public_html/megalibrary/session.php on line 6
>
> PHP Warning: session_start(): Cannot send session cookie - headers
> already sent by (output started at
> /home/consolem/public_html/megalibrary/index.php:2) in
> /home/consolem/public_html/megalibrary/session.php on line 3
>
> PHP Warning: session_start(): Cannot send session cache limiter -
> headers already sent (output started at
> /home/consolem/public_html/megalibrary/index.php:2) in
> /home/consolem/public_html/megalibrary/session.php on line 3
Kindly check my session.php code:
<?php
//Start session
session_start();
//Check whether the session variable SESS_MEMBER_ID is present or not
if (!isset($_SESSION['id']) || (trim($_SESSION['id']) == '')) {
header('location: login.php');
exit();
}
$session_id=$_SESSION['id'];
?>
Kindly check the line no. 2 of my index.php:
<?php include('session.php'); ?>
Whats wrong in my code ? I would really appreciate if anyone can guide to to solve these errors.
Thanks in advance.