会话变量在子目录中不可访问 [英] Session variables not accessible in subdirectory

查看:179
本文介绍了会话变量在子目录中不可访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们将项目从Beta测试服务器移到实时服务器时,我们经历了以下事情:

When we moved our project from the beta test server to our live server we experienced the following:

仅当访问它们的文件与创建它们的文件位于同一文件夹中时,才能访问它们.在我们的Beta版服务器上并非如此.因此,我创建了三个非常简单的测试文件:

Session variables are only accessible if the file accessing them is in the same folder as the file that created them. This was not the case on our beta server. So I've created three very simple test files:

test.php

<?php
session_id("581186accf44d7e80df40d0b5a47fb7d");
session_start(); 
$_SESSION['myvariable'] = 'Hello World';
?> 
<html>
    <body>
        <p><a href="page2.php">Same folder test</a></p>
        <p><a href="test/page2.php">Subfolder test</a></p>
    </body>
</html>

然后,将以下文件复制到同一文件夹和test/文件夹中.

Then we have the following file duplicated in the same folder and in the test/ folder.

page2.php

<?php 
session_start();
print 'Here is page two, my session variable and my session cookie: '; 
print $_SESSION['myvariable']; 
print $_COOKIE['PHPSESSID'];
exit; 
?>

,结果如下: page2.php

and here are the results: page2.php

Here is page two, my session variable and my session cookie: Hello
World581186accf44d7e80df40d0b5a47fb7d

test/page2.php

test/page2.php

Here is page two, my session variable and my session cookie: 581186accf44d7e80df40d0b5a47fb7d

如您所见,会话变量已消失.但是会话ID cookie保留在子目录中,所以这不是cookie问题.

As you can see, the session variable has disappeared. But the session ID cookie is preserved in the subdirectory, so it isn't a cookie issue.

我已经在phpinfo()中查看了会话块;除了在beta服务器上设置但不在实时服务器上设置的session.save_path之外(这可能意味着它将默认为/tmp),两者的配置相同.

I've looked at the session block in phpinfo(); and aside from session.save_path, which is set on the beta server but not on the live server (which presumably means it will default to /tmp), the configuration is identical on both.

此外,我们没有.htaccess文件,该文件可能会将domain.com路径更改为www.domain.com路径.

Also, we don't have a .htaccess file which might change domain.com paths to www.domain.com paths.

由于此测试可在我们的Beta服务器上运行,因此我得出结论,这是一个php配置问题,但是如果有人可以将我指向需要更改的参数,那将不胜感激!

Because this test works on our beta server, I have concluded that it's a php configuration issue, but if someone could point me toward the parameter that needs changing, that would be much appreciated!

推荐答案

好吧,看来出现了问题,部分原因是由于我不了解将自己的php.ini放入public_html文件夹会做什么. 因为我们无法在共享服务器上使用ini_set()(已禁用),所以我创建了php.ini的本地副本,其中包含以下几行以覆盖过时的默认设置...

Ok, it appears that the problem occurred, in part, due to my lack of understanding of what putting my own php.ini in the public_html folder would do. Because we can't use ini_set() on our shared server (it's disabled) I created a local copy of php.ini that contained the following lines to override dud default settings...

date.timezone =  Australia/Melbourne
magic_quotes_gpc = Off

我假设此本地版本php.ini中的值将简单地覆盖主php.ini中的值.

I assumed that the values in this local version of php.ini would simply override the values in the master php.ini.

不幸的是,这不是在Jumba/UberGlobal托管上发生的. 创建此本地php.ini意味着,除了这两个设置之外,整个配置都恢复为默认值.

Unfortunately this is not what happens on the Jumba / UberGlobal hosting. Creating this local php.ini meant that the entire configuration reverted to default values, except for these two settings.

该解决方案是针对Jumba/Uberglobal的技术人员复制其php.ini文件(仅更改了上述两个值)并将其放置在我们的public_html文件夹中.

The solution was for a tech from Jumba / Uberglobal to make a copy of their php.ini file (with just the above two values changed) and place it in our public_html folder.

这已解决了问题.

感谢大家的帮助!

这篇关于会话变量在子目录中不可访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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