can I include my session_start() in my header include or should I past session_start() in every pages? Is there any pros or cons in pasting the session_start() in the header include?
+3
A:
session_start() should probably be one of the first lines. you have to start the session before any data is output. if you're using includes to simulate a template system then stick it in the page controller.
daedalus0x1a4
2010-06-26 00:51:08
+1
A:
The only real downside is if you ever want a session-less page. Then you'll have to have some convention to disable it.
<?php
define( 'NO_SESSION', true );
include( 'header.php' );
?>
header.php
<?php
if ( !defined( 'NO_SESSION' ) )
{
session_start();
}
Peter Bailey
2010-06-26 00:51:21
If you want to have a session-less page, you just don't call any $_SESSION variable :-)
Vinko Vrsalovic
2010-06-26 00:51:58
@Vinko, no, you'll still be loading the user session—which takes (some) time.
aharon
2010-06-26 00:55:17
well, i want to ask why you would want a session-less page in some parts of the application but not others. in that case you should be able to easily call session_destroy()
daedalus0x1a4
2010-06-26 01:04:01
@aharon: True, although I really think that it would be worthwhile in very few cases (when you want a very fast page that gets called a lot that doesn't use the session at all and your session variables are usually big.)
Vinko Vrsalovic
2010-06-26 06:56:59