What I did is created a php code to check login status (file name:login_status):
<?php
session_start()
// code body to check if session or cookies are set
// If not, then variable $loggedin = false, else true
// if true then redirect to profile page
// if false then redirect to login page
?>
But when I include this file above any code using include_once("login_status.php");, then php script stops execution (if $loggedin == false) instead of redirecting to login page and if$loggedin == true the redirect it to profile page.
What I did is, instead of using include_once("login_status.php");, I simple copied the code of login_status above any page where I need it. After that its working fine.
I am not able to figure it out what does include_once makes a difference?
However, its true that session_start() should be on the top, before anything. But does include_once makes any difference on that?