开发者

Starting global session to all pages

How can i start a session in PHP which will be global to all my pages. I don't have access to th开发者_开发知识库e php.ini file. So session.auto_start = 0 in my php.ini will not be a solution for me.

Thanks.


$_SESSION is a global.

Start it off by calling session_start() before any output.


session_start(); 

Place this at the top of your pages and it will start a session. You can access it and set its variables with $_SESSION['somevalue']. Also you can name the session using session_name("some name");


If you want all pages to automagically have a session_start(), without actually writing the code, you're pretty much stuck with ini-settings. It is very well possible that although you cannot alter php.ini in a shared environment (proper hosters do offer a custom ini IMO), that you can just add the php_flag session.autostart = 1 to an .htaccess file in the root.


Nothing bad in starting a session with session_start() - everyone doing that.
Don't you have some config file already, which being included into every script on the site? If yes - why not to put session_start there? If not - you have to think of having one.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜