简体   繁体   English

会话数据未保存

[英]Session data not saving

I am debugging a php session that worked when I last tested it, a couple of months ago. 我正在调试一个几个月前最后一次测试的php会话。 The code has not changed in any way, but the session has now stopped working. 代码没有任何改变,但是会话现在已经停止工作。

I have read multiple questions here as well as other articles but no suggestions have solved this problem. 我在这里以及其他文章中已经阅读了多个问题,但是没有任何建议可以解决这个问题。 I believe my code is correct, but when I asked support at Bluehost, they say it must be a code problem: 我相信我的代码是正确的,但是当我向Bluehost请求支持时,他们说这一定是代码问题:

I am starting a session and setting a few session variables: 我正在开始一个会话并设置一些会话变量:

<?php
    session_start();

$_SESSION["franchise_name"] = $_POST["name"];
$_SESSION["db_name"] = $_POST["name"];
$_SESSION["franchise_location"] = $_POST["franchise_location"];
$_SESSION["franchise_phone"] = $_POST["franchise_phone"];
$_SESSION["franchise_address"] = $_POST["franchise_address"];
$_SESSION["franchise_email"] = $_POST["franchise_email"];

header("Location: session.php"); /* Redirect browser */
exit;

?>

If I echo the session variables immediately after setting them, all is well. 如果我在设置它们后立即回显会话变量,一切都很好。 Good stuff. 好东西。 So I know everything works in this section. 因此,我知道本节中的所有内容均适用。

session.php looks like this: session.php看起来像这样:

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
    session_start();
echo 'Testing Output:';
echo session_status();
echo '<pre>';
var_dump($_SESSION);
echo '</pre>';
phpinfo();
?>

So when I test this, no data is being passed in the session. 因此,当我对此进行测试时,会话中不会传递任何数据。 The output on session.php is: session.php的输出是:

Testing Output:2
array(0) {
}

I also set up a tester to see if session data is enabled: 我还设置了一个测试器,以查看是否启用了会话数据:

<?php
// Start Session
session_start();
// Show banner
echo '<b>Session Support Checker</b><hr />';
if (!is_writable(session_save_path())) {
    echo 'Session path "'.session_save_path().'" is not writable for PHP!<br />'; 
} else {
    echo 'Session path "'.session_save_path().'" is writable for PHP!<br />'; 

}
// Check if the page has been reloaded
if(!isset($_GET['reload']) OR $_GET['reload'] != 'true') {
   // Set the message
   $_SESSION['MESSAGE'] = 'Session support enabled!<br />';
   // Give user link to check
   echo '<a href="?reload=true">Click HERE</a> to check for PHP Session Support.<br />';
} else {
   // Check if the message has been carried on in the reload
   if(isset($_SESSION['MESSAGE'])) {
      echo $_SESSION['MESSAGE'];
   } else {
      echo 'Sorry, it appears session support is not enabled, or you PHP version is to old. <a href="?reload=false">Click HERE</a> to go back.<br />';
   }
}
?>

The result of this test shows that the session data didn't work here either and that the session path is indeed writable. 该测试的结果表明,会话数据在这里也不起作用,并且会话路径确实是可写的。 Phpinfo shows that sessions are enabled. Phpinfo显示已启用会话。

Is there anything else I can try to help me troubleshoot this issue? 还有什么我可以尝试帮助解决此问题的方法吗? Thanks. 谢谢。

Update: I did try seeting the session path with ini_set(' session.save_path','SOME WRITABLE PATH'); 更新:我确实尝试使用ini_set('session.save_path','SOME WRITABLE PATH')查看会话路径; but that did not solve the problem. 但这并不能解决问题。

from php session_start() page: 从php session_start()页面:

Note : 注意事项
To use cookie-based sessions, session_start() must be called before outputing anything to the browser. 要使用基于cookie的会话,必须在将任何内容输出到浏览器之前调用session_start()

remove the spaces before session_start() , they are considered output. 删除session_start()之前的空格,它们被视为输出。


Update: 更新:

It can also be related to the location of the session files, you may try setting a new location: 它也可能与会话文件的位置有关,您可以尝试设置一个新位置:

ini_set('session.save_path','/some/safe/path/to/sessions');
session_start();

Make sure sessions has the appropriate permissions 确保sessions具有适当的权限

I called Blue Host - this second support person was more alert than the first and recognized that Varnish Caching could cause the problem. 我给Blue Host打了电话-第二个支持人员比第一个更警惕,并且意识到Varnish Caching可能会引起问题。 We disabled it and voila! 我们禁用了它,瞧! Fixed. 固定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM