我们可以在 php 中创建无休止的会话吗? [英] Can we create endless session in php?

查看:42
本文介绍了我们可以在 php 中创建无休止的会话吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,当用户关闭浏览器时,php 会话就会过期.是否可以在 php 中创建一个永不过期的会话,不管用户关闭和重新启动浏览器多少次?

Normally a php session expires when the user closes the browser. Is is possible to create a session in php that never expires, doesn't matter how many times user closes and restart the browser?

谢谢

推荐答案

严格来说不是无限的,但是你可以将 cookie 的生命周期设置为两年左右,这非常接近:

Not strictly endless, but you can set the cookie lifetime to two years or so which comes pretty close:

  • session.cookie-lifetime ini setting
  • session_set_cookie_params()Docs function to set them programmatically.

如果用户关闭浏览器,会话 cookie 不会被删除.

The session cookie won't be deleted then if the user closes the browser.

注意您的会话数据存储 保持数据也那么长.这个很重要.请记住,您需要存储这么长的时间跨度内的所有用户数据,因此您应该有足够的可用空间.

Take care that your session data store keeps the data as well that long. This is important. And keep in mind that you need to store all user's data for this large time-span, so you should have enough space available.

如果用户在她或他的浏览器中禁用了 cookie,这根本不起作用.

This does not work at all if the user disables cookies in her or his browser.

这篇关于我们可以在 php 中创建无休止的会话吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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