开发者

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();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜