当我在codeigniter 3.0.4控制器中加载会话库时立即面临错误


facing error as soon as I load session library in my codeigniter 3.0.4 controller

我已经看到并检查了其他堆栈溢出问题,这个问题的常见答案是

确保 <?php 标记前没有空格

即使在浏览了有关此问题的其他博客和文章后,我仍然面临相同的错误。但是如果我删除会话的负载,一切正常。

我的错误:

A PHP Error was encountered
Severity: Warning
Message: mkdir() [function.mkdir]: No such file or directory
Filename: drivers/Session_files_driver.php
Line Number: 117
Backtrace:
File: /home/content/97/8248497/html/dvjtest/application/controllers/Home.php
Line: 9
Function: library
File: /home/content/97/8248497/html/dvjtest/index.php
Line: 292
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /home/content/97/8248497/html/dvjtest/system/core/Exceptions.php:272)
Filename: core/Common.php
Line Number: 568
Backtrace:
An uncaught Exception was encountered
Type: Exception
Message: Session: Configured save path '' is not a directory, doesn't exist or cannot be created.
Filename: /home/content/97/8248497/html/dvjtest/system/libraries/Session/drivers/Session_files_driver.php
Line Number: 119
Backtrace:
File: /home/content/97/8248497/html/dvjtest/application/controllers/Home.php
Line: 9
Function: library
File: /home/content/97/8248497/html/dvjtest/index.php
Line: 292
Function: require_once

我的控制器:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends CI_Controller {
    public function __construct()
    {
        parent::__construct();
        $this->load->library('session');
        $this->load->helper('url');
        $this->load->helper('cookie');
    } 
    public function index()
    {
        $this->load->view('header');
        $this->load->view('welcome_message');
        $this->load->view('footer');
    }
}
?>

会话库正在尝试写入磁盘,这恰好也涉及 mkdir()。您需要使该路径可写,或者将会话数据目录更改为已可写的其他内容。

选中配置中的"sess_save_path"。有关会话配置的更多文档:https://www.codeigniter.com/user_guide/libraries/sessions.html#session-preferences

更改(config/config.php code igniter 3.0.4 上的第 # 374 行)

$config['sess_save_path'] = 'NULL';

$config['sess_save_path'] = BASEPATH.'ci_sessions';

https://www.codeigniter.com/user_guide/libraries/sessions.html

注意

如果您已从以前版本的 CodeIgniter 升级,并且您 没有配置"sess_save_path",则会话库将 查找旧的"sess_table_name"设置并改用它。请 不要依赖此行为,因为它将来会被删除。