本文介绍了跨同域子页面的 PHP 会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个域 (domain.com),其中包含多个具有不同会话的子页面(默认情况下),我希望其中一些子页面共享一个会话.

I have one domain (domain.com) with multiple sub-pages that have different sessions (by default) and I want some of those sub-pages to share a session.

例如,我有 domain.com/section1/staff/domain.com/section2/staff/.我正在使用 $_SESSION 变量来存储当前登录用户的信息,我希望能够在 section1/staff/ 中登录一次并仍然登录当我去section2/staff/.

So for example I have domain.com/section1/staff/ and domain.com/section2/staff/.I am using the $_SESSION variable to store info on the currently logged in user and I want to be able to log in once in section1/staff/ and still be logged in when I go to section2/staff/.

从阅读其他帖子来看,这似乎是默认方式会话应该可以工作,并且在两个页面中都没有设置域,并且 session_get_cookie_params() 中的路径是/",所以它应该是同一个会话,但它不共享 $_SESSION 变量,即使我调用 session_destroy() 它也不会破坏另一个会话.

From reading other postings it seems like this is the default way that sessions should work and in both pages the domain isn't set and the path is "/" in session_get_cookie_params() so it should be the same session but it's not sharing the $_SESSION variable and even when I call session_destroy() it doesn't destroy the other session.

有没有办法显式地将它们设置为使用相同的(或其他地方来查找不会出现在 session_get_cookie_params() 数组中的默认设置)?

Is there a way to explicitly set them to use the same (or another place to look for default settings that wouldn't show up in the session_get_cookie_params() array)?

推荐答案

问题是一个部分将 URL 强制为 domain.com,另一部分将其强制为 www.domain.com.

The problem was that one section forced the URL to domain.com and the other forced it to www.domain.com.

这篇关于跨同域子页面的 PHP 会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 21:45