When we moved our project from the beta test server to our live server we experienced the following:
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>
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;
?>
and here are the results:
page2.php
Here is page two, my session variable and my session cookie: Hello
World581186accf44d7e80df40d0b5a47fb7d
test/page2.php
Here is page two, my session variable and my session cookie: 581186accf44d7e80df40d0b5a47fb7d
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.
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.
Also, we don't have a .htaccess file which might change domain.com paths to www.domain.com paths.
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!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…