如何在php中包含页面中使用session [英] how do use session in included page in php
问题描述
嗨所有
i开始编程简单的cms
i创建了一个索引,联系人,faq ,...所有这些页面使用的页面 header.php 和 footer.php
现在我有一些问题,如使用会话
如果我在标题,此代码在所有页面中重复使用来自header.php ...并且此操作可能冲突而不是其他页面
什么是使用代码的最佳解决方案(如会话或cookie)在共享页面(如header.php)?
请帮帮我
非常感谢
你可以调用session_start您喜欢的时间,如果会话已经打开,它将不会以任何形式更改它。不过,我建议将它放在一个实用程序文件中,在包含任何其他内容之前包含它,首先,在响应主体中写入任何内容之前(除非您使用输出缓冲)。我通常创建一个config.php文件,其中包含所有必要的配置设置和初始化过程,包括启动会话。
注意:如果是无cookie会话,您可能还需要考虑其他因素。 / BLOCKQUOTE>
hi all
i start a programming of simple cms
i created a index , contact , faq , ... page that all of these pages use from 2 files header.php and footer.php
now i have a problem with some code like usage session
if i use session_start() function in header , this code repeat in all page that use from header.php ... and this action maybe do conflict over than other page
what is a best solution for use code (like session or cookie) in a shared page (like header.php) ?
please help me
thanks a lot解决方案You can call session_start as many times you like, if a session is already opened it won't change it in any form. Still, I suggest to put it in an utility file, that you include before including anything else, and first of all, before writing anything in the response body (except if you use output buffering). I am usually creating a config.php file, that contains all necessary configuration settings and initialization procedures, including starting session.
A note: in case of cookieless session you might need to have other considerations too.
这篇关于如何在php中包含页面中使用session的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!