页面之间的 PHP 会话 ID 更改 [英] PHP Session Id changes between pages

查看:26
本文介绍了页面之间的 PHP 会话 ID 更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,我在 2 个页面之间丢失了 PHP 会话.

I have a problem where i am losing the PHP session between 2 pages.

session_start() 包含在名为 session-inc.php 的文件中,每个页面都需要设置会话.这适用于站点上的所有页面,除了一个特定页面,member-profile.php.当访问此页面时,将设置并使用具有不同 id(相同会话名称)的新会话.

The session_start() is included in a file called session-inc.php into every page requiring a session to be set. This works for all pages on the site except one particular page, member-profile.php. When this page is visited a new session with a different id (same session name) is set and used instead.

更多细节:

  • 手动设置会话名称
  • 所有页面都在同一个域名下的同一台服务器上
  • 如果我在 member-profile.php 文件中的 include('session-inc.php') 上方添加了一个额外的 session_start(),会话将正确进行
  • 我尝试在 .htaccess 中设置 session_cookie_domain 和 session.session_name,这适用于该域,但它阻止了会话被传递到支付域
  • 我们正在使用 php 5.2.5 运行 apache 2.2.6

将 session_start() 放在 member-profile.php 文件中的 include('session-inc.php') 之上是解决此问题的快速而肮脏的方法,但我想知道是否有人知道为什么会发生这种情况.

Putting the session_start() above the include('session-inc.php') in the member-profile.php file is the quick and dirty fix for this problem, but i am wondering if anybody know why this would be happening.

干杯

推荐答案

根据 PHP 文档,session_start 必须在任何输出发送回浏览器之前调用 - 此页面是否可能有恶意 CR/LF、Unicode 字节顺序标记或类似的导致include('session-inc.php')?

According to PHP documentation, session_start must be called before any output is sent back to the browser-- could this page have a rogue CR/LF, Unicode byte-order mark or similar that is causing output before you include('session-inc.php')?

这篇关于页面之间的 PHP 会话 ID 更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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