我什么时候必须声明 session_start();? [英] When do I have to declare session_start();?
问题描述
所以我是 PHP 的初学者,所以我需要一点帮助.我想弄清楚何时开始会话.我应该在用户第一次注册时做还是在他们登录时做?
So Im a beginner when it comes to PHP so I need a little help. I am trying to figure out when to start the session. Should I do it when the user first registers or what about when they log in?
此外,会话是通用"的意思,当我检查会话时它会起作用还是我必须在所有页面中包含一个文件来检查是否有人有会话?
Also, are sessions 'universal' meaning when I check a session will it work or do I have to include a file to all pages that check if someone has a session?
推荐答案
我应该在用户第一次注册时做还是在他们登录时做?"
您应该每次都这样做,以获取或设置任何会话信息.存储在 $_SESSION
数组中的数据只有在会话开始后才可用.
You should do it every time you want to get or set any session information. Data stored in the $_SESSION
array will only be available after the session is started.
此外,会话是通用的"意味着当我检查会话时它会起作用还是我必须在所有页面中包含一个文件来检查是否有人有会话?
调用 session_start()
即可创建会话.如果已创建会话,则将使用该会话.
Calling session_start()
is all you need to create a session. If a session was already created, that session will be used.
这篇关于我什么时候必须声明 session_start();?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!