session_id、session_regenerate_id 和 session_name 有什么用? [英] What are session_id, session_regenerate_id and session_name used for?
问题描述
好吧,我是会话的新手,让我们想象一下我们有一个小登录站点,
ok im a newbie on sessions lets imagine that we have a little login site,
这是一个逻辑
- 登录
- 如果密码正确 = 使用 $_SESSION[isaloginuser] = 1
- 如果 $_SESSION[isaloginuser] = 1,检查会话以查看菜单
- 显示菜单
- 用户想要注销
- 取消设置会话
- 破坏会话系统
用途
session_register
session_destroy
session_unset
session_start
session_id
在哪里?session_regenerate
或 session_name
进去了吗?在 php 网站上它说
where does the session_id
& the session_regenerate
or session_name
goes in ?
at php site it says
session_id() 用于获取或设置当前会话的会话 ID.
session_id() is used to get or set the session id for the current session.
我还是不明白,我们为什么需要它们?在真实环境它有什么作用?
i still just dont get it, why do we need them anyway ? in real environment what does it do ?
推荐答案
不,你不需要使用它们.一般来说,您只需要
No, you don’t need to use them. In general all you need is
session_start
开始会话处理,以及session_destroy
销毁存储的会话数据(这不会修改$_SESSION
) 和session_unset
以重置$_SESSION
变量(但你也可以做$_SESSION = array()
).
session_start
to start the session handling, andsession_destroy
to destroy the stored session data (this does not modify$_SESSION
), andsession_unset
to reset the$_SESSION
variable (but you can also do$_SESSION = array()
).
session_id
和 session_name
用于获取和设置当前会话ID和会话ID名称(默认为PHPSESSID
).session_regenerate_id
可用于重新生成/更改当前会话的会话 ID.例如,如果您希望每 10 分钟或在更改与会话关联的用户的真实性状态后刷新会话 ID,这可能很有用.
session_id
and session_name
are to get and set the current session ID and session ID name (default is PHPSESSID
). session_regenerate_id
can be used to regenerate/change the session ID of the current session. This might be useful if, for example, you want to refresh the session ID every 10 minutes or after changing the state of authenticity of a user associated with a session.
这篇关于session_id、session_regenerate_id 和 session_name 有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!