为什么 PHP 不在页面之间保持会话? [英] Why does PHP not keep session between pages?

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

问题描述

我有一台带有 apache2 的 Windows Server 2008.服务器有 2 个光盘,我在两个光盘上都运行了一个 apache 实例.第一个作为服务运行,第二个在命令行中运行.他们都在自己的 htdocs 文件夹中使用完全相同的 webroot 副本.此外,它们都使用位于第一张光盘(Program Files (x86))上的相同 PHP 安装.我的应用程序通过 SSL 运行并使用 PHP 和 MySQL.

I have a Windows server 2008 with apache2. The server has 2 discs and I run an apache instance on both. The first runs as a service the second in the commandline. They both use an exact copy of an identical webroot in their own htdocs folder. Also they both use the same PHP install that is located on the first disc (Program Files (x86)). My application runs over SSL and uses PHP and MySQL.

作为服务运行的网络服务器可以很好地运行我的应用程序,并让我随时登录并准备好我的会话数据.然而,第二台服务器让我运行我的登录脚本,在运行脚本时有会话数据,但在重定向到同一个 webroot 内的另一个页面后丢失了该会话数据.

The webserver that runs as a service runs my application fine and lets me login and has my session data ready at all times. The second server however lets me run my login script, has session data while running the script but loses that session data after a redirect to another page inside the same webroot.

第二个网络服务器上的问题类似于这个问题 除了我在每个页面上都有 session_start() .

The problem on the second webserver is similar to this question with the exception that I have session_start() on every page.

我的登录脚本是这样工作的:

My login script works like this:

  • 用户请求页面
  • 如果用户未通过身份验证,他将返回登录页面
  • 如果用户通过身份验证,他将获得 $_SESSION["auth"] 及其个人资料数据
  • 然后,当用户浏览主页或其他需要身份验证的页面时,他们只需检查是否设置了 $_SESSION["auth"].

有关如何解决此问题的任何提示?

Any tips on how to solve this?

一个小的澄清.我在每个页面上都有一个会话 ID.当我被重定向时,该 ID 不会改变.我重定向到的页面上的 $_SESSION 变量中没有任何数据.

A small clarification. I do have a session ID on each page. That id does not change when I get redirected. I do NOT have any data in the $_SESSION variable on the page I redirect to.

推荐答案

查看存储会话文件的 php 会话目录的权限.如果 php 没有写入、创建和更改文件的权限,您将无法在 $_SESSION 变量中存储任何内容.

Look at the permissions of the php session directory where the files for the session are being stored. If php doesn't have the rights to write, create and change files you won't be able to store anything in your $_SESSION var.

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

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