Hai folks,
is it true that session_start() should be called on the very first line of the php page even though the usage of the session variable may be in the middle of the page?

because i had a problem today that session varaiaible and solved after moving the session_start() to the first line.
before when problem exist :
PHP Code:
ini_set('display_errors','1');
require_once("../../../includes/connection.php");
require_once("../../../includes/checkpoint.php");
require_once("../../../includes/set_time_zone.php");
require_once("../../../includes/session_start.php"); //see below for the content of this file
unset($empno);
$empno=$_SESSION['empno'];
content of session_start.php
PHP Code:
if(session_id() == '') {
session_start();
}
then the problem solved after moving the session_start.php to the top
PHP Code:
require_once("../../../includes/session_start.php");
ini_set('display_errors','1');
require_once("../../../includes/connection.php");
require_once("../../../includes/checkpoint.php");
require_once("../../../includes/set_time_zone.php");
unset($empno);
$empno=$_SESSION['empno'];
Bookmarks