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条)

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程