session_id、session_regenerate_id 和 session_name 有什么用? [英] What are session_id, session_regenerate_id and session_name used for?

查看:49
本文介绍了session_id、session_regenerate_id 和 session_name 有什么用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我是会话的新手,让我们想象一下我们有一个小登录站点,

ok im a newbie on sessions lets imagine that we have a little login site,

这是一个逻辑

  1. 登录
  2. 如果密码正确 = 使用 $_SESSION[isaloginuser] = 1
  3. 如果 $_SESSION[isaloginuser] = 1,检查会话以查看菜单
  4. 显示菜单
  5. 用户想要注销
  6. 取消设置会话
  7. 破坏会话系统

用途

session_register
session_destroy
session_unset
session_start

session_id 在哪里?session_regeneratesession_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 to start the session handling, and
  • session_destroy to destroy the stored session data (this does not modify $_SESSION), and
  • session_unset to reset the $_SESSION variable (but you can also do $_SESSION = array()).

session_idsession_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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆