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

时间:2016-02-05 20:51:55

标签: php codeigniter session

我已经看过并检查过其他stackoverflow问题,这个问题的常见答案是

  

确保<?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');
    }
}

?>

2 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分:1)

更改(Codeigniter 3.0.4上的config / config.php第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 ”设置并改为使用它。请   不要依赖这种行为,因为它将来会被删除。