Page 1 of 1

session_start() placement

Posted: Thu Mar 25, 2004 3:03 pm
by Steveo31
This has to be in the top of the page, start of the first <?php right? For example:

Code: Select all

<?php

session_start();
include ('header.php');

$var1 = $_POST['var'];

// so on
I've seen it in various places in other's code...

Posted: Thu Mar 25, 2004 3:06 pm
by markl999
It just needs to come before any output so the first line of the script makes it a logical choice.
I usually have it after all the defines, requires etc.

Posted: Thu Mar 25, 2004 3:10 pm
by Steveo31
:)

Posted: Thu Mar 25, 2004 4:28 pm
by aleigh
markl999 wrote:It just needs to come before any output so the first line of the script makes it a logical choice.
I usually have it after all the defines, requires etc.
If I am building a larger system I tend to put it in a site-wide include, up at the top. The earlier the better, because invariably there will be some file that has a blank line at the buttom that constitutes "output" haha especially if multiple people are working on the project.