0

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?

user15
  • 1,048
  • 10
  • 19
user2105650
  • 31
  • 1
  • 4

1 Answers1

0

its true that session_start() should be on the top, before anything.

Not before anything, but before any output.

Also, please, make yourself familiar with error reporting and make appropriate settings to be able either see errors on-screen(on a development server) or logged (on a production) - so, there would be no need for guess anything.

on a development server make changes in php.ini

error_reporting = E_ALL
display_errors = On

production

error_reporting = E_ALL
display_errors = Off
log_errors = On
Your Common Sense
  • 154,967
  • 38
  • 205
  • 325