会话保持活动状态

会话保持活动状态

本文介绍了什么使 php 会话保持活动状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

会话仅在您每次使用 session_start(); 访问页面时才保持活动状态,还是其他页面也保持活动状态?

示例(30 分钟超时):

1

用户通过 session_start() 访问页面;
25 分钟后,他们访问另一个 session_start();
页面会话保持活动

2

用户通过 session_start() 访问页面;
25 分钟后,他们访问了非 session_start();页面
会话保持活动

2 也是真的吗?

解决方案

每当您访问具有 session_start() 的页面时,浏览器中总会设置一个会话 cookie.如果网站使用 PHP,cookie 名称将为 PHPSESSID(尽管名称可以更改).此会话 cookie 包含一个会话 ID,可帮助浏览器与服务器保持该会话.

您可以通过浏览任何有您会话的网站手动检查,然后删除您的浏览器cookie,您的会话将丢失.

在你的情况下 1 &2 是正确的.

2 是正确的,因为用户已经访问了具有 session_start() 的页面,并且您的会话 ID 将在接下来的 30 分钟内设置,即使您访问的页面没有会话.

注意:但是如果您将访问的页面包含session_destroy(),您的会话将被销毁.

Are sessions only kept alive each time you access a page with session_start(); or do other pages keep it alive too?

Example (with 30 minute timeout):

1

2

Is 2 also true ?

解决方案

There is always a session cookie set in your browser whenever you access a page which has session_start(). The cookie name will PHPSESSID if the website is using PHP(although the name can be changed). This session cookie contains a session id which helps the browser to maintain that session with the server.

You can check manually by browsing any website which has your session and then delete your browser cookies, your session will be lost.

In your case both 1 & 2 are correct.

2 is correct because the user already has accessed a page which has session_start() and your session id will be set for the next 30 mins and it will be present even if you accesse a page which does not have a session.

NOTE: But the page which you will be visiting if contains session_destroy(), your session will be destroyed.

这篇关于什么使 php 会话保持活动状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 07:08