PHP session_start() question?
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 in开发者_如何学Goclude?
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.
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();
}
精彩评论