dongzhi1851 2015-04-29 14:37
浏览 36
已采纳

未定义的变量:_SESSION [CORE / src / Network / Session.php CakePHP 3.0

I am using CakePHP 3.0, and uploaded it to the server, it was working fine in local but somehow after uploading it to server it shows error

Notice (8): Undefined variable: _SESSION [CORE/src/Network/Session.php, line 438]

If any have idea about that please help me. I am still trying to solve it.
I have also tried to put session_start(); in AppController and many other places but then it goes blank.

  • 写回答

3条回答 默认 最新

  • dongyan5706 2015-05-11 09:44
    关注

    I have found the issue, Its when I was uploading the files to servers it was automatically appending the white blank lines at the end of the AppController and also another controller files.

    So when I removed the blank lines from that files it is working fine again

        //To detect the file which have issue or extra space or early header start
    //File location : vendor/cakephp/cakephp/src/Network/Session.php 
        public function write($name, $value = null)
                {
                    if (empty($name)) {
                        return;
                    }
    
                    if (!$this->started()) {
                        $this->start();
                    }
    
                    $write = $name;
                    if (!is_array($name)) {
                        $write = [$name => $value];
                    }
    
                    //remove the comment from bottom line and run your code it will 
                    //show you the exact file from where you have to remove the blank space
                    //session_start();
                    $data = $_SESSION ?: [];
                    foreach ($write as $key => $val) {
                        $data = Hash::insert($data, $key, $val);
                    }
    
                    $this->_overwrite($_SESSION, $data);
                } 
    

    Small issue but took long time to detect it,hope this will help you all.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 人大金仓下载,有人知道怎么解决吗
  • ¥15 一个小问题,本人刚入门,哪位可以help
  • ¥15 python安卓开发
  • ¥15 使用R语言GD包一直不出结果
  • ¥15 计算机微处理器与接口技术相关问题,求解答图片的这个问题,有多少个端口,端口地址和解答问题的方法和思路,不要AI作答
  • ¥15 如何根据一个截图编写对应的HTML代码
  • ¥15 stm32标准库的PID角度环
  • ¥15 ADS已经下载好了,但是DAS下载不了,一直显示这两种情况,有什么办法吗,非常急!
  • ¥100 Excel 点击发送自动跳转outlook邮件
  • ¥15 gis中用栅格计算器或加权总和后图层不显示,值也明显不对