简体   繁体   English

在一个 CodeIgniter controller session 是空的,在其他所有作品

[英]In one CodeIgniter controller session is empty, in other all works

I developed this functionality locally on my laptop and all worked well, but when I uploaded changes on the server, I received an issue.我在笔记本电脑上本地开发了这个功能并且一切正常,但是当我在服务器上上传更改时,我收到了一个问题。

The check_admin_auth() function checks session variable and it is NULL when it calls from my controller (all other controllers in the project with the same code works well). The check_admin_auth() function checks session variable and it is NULL when it calls from my controller (all other controllers in the project with the same code works well).

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Ctransaction extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->auth->check_admin_auth(); // this function
         /* checks one session item to check is user logged and admin or not,
            if not - redirects to login page. But in my case redirecting doesn't apply,
            I see just white screen, page status 200. */
        $this->db->query('SET SESSION sql_mode = ""');
    }

    public function index()
    {
        // some code here
        $content = $this->parser->parse('gltransaction/list', $data, true);
        $this->template->full_admin_html_view($content);
    }

    public function ajaxLoadGLTransactions()
    {
        // some code here
        echo json_encode($result);
    }
}

Please, can you help me to find where the problem is?拜托,你能帮我找出问题所在吗? I think that's settings in php.ini or in the same place, but I didn't find a reason.我认为这是php.ini或同一个地方的设置,但我没有找到原因。

I tried to modify /system/libraries/Session/Session.php as it was recommended in web, but it didn't help.我尝试按照 web 中的建议修改/system/libraries/Session/Session.php ,但没有帮助。

Files with sessions are created in folder /application/ci_sessions and they stored all necessary data, but for some reason, my controller doesn't load it and returns on its page session with only one field - __ci_last_regenerate .带有会话的文件是在文件夹/application/ci_sessions中创建的,它们存储了所有必要的数据,但由于某种原因,我的 controller 没有加载它并在其页面 session 上返回,只有一个字段 - __ci_last_regenerate

The library session is loaded in autoloader in configuration file.库 session 在配置文件的自动加载器中加载。

Cookies are the same on working pages and on page of my controller. Cookies 在工作页面和我的 controller 页面上是相同的。

CI Version 3.1.4 CI 版本 3.1.4

PHP Version 7.2.32 PHP 版本 7.2.32

The problem was that before <?php I've added one more line.问题是在<?php之前我又添加了一行。 The file of controller was like: controller 的文件是这样的:

// empty line without anything
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
// and all other code

Didn't think that it can make sense!没想到还能说得通!

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

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