Applying Codeigniter 3 to a new domain host gives mkdir() error for session_files_drive.php

烈酒焚心 提交于 2019-12-02 11:17:19

问题


I have a Codeigniter framework setup that I move cross multiple domain setups as a default starting point. It gives me the below error. It is the same when I added a clean install of CI3 and added database info, and theese following autoloads:

$autoload['libraries'] = array('database', 'session', 'user_agent', 'upload');
$autoload['helper'] = array('form', 'url');

I tried removing the 'session', library and the error went away.

Below you see the error:

A PHP Error was encountered
Severity: Warning

Message: mkdir(): Invalid path

Filename: drivers/Session_files_driver.php

Line Number: 136

Backtrace:

File: /customers/9/0/3/***.***/httpd.www/index.php
Line: 315
Function: require_once

A PHP Error was encountered
Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /customers/9/0/3/***.***/httpd.www/system/core/Exceptions.php:271)

Filename: core/Common.php

Line Number: 564

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: /customers/9/0/3/***.***/httpd.www/system/libraries/Session/drivers/Session_files_driver.php

Line Number: 138

Backtrace:

File: /customers/9/0/3/***.***/httpd.www/index.php
Line: 315
Function: require_once

I have hidden the domain name. Sorry for that, but I dont think thats extremly vital.

Here is my config for sessions:

$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

回答1:


If you use Codeigniter's /default) file session storage driver, you need to keep in mind that it only supports absolute paths for $config['sess_save_path']

the config.php states:

|   The location to save sessions to, driver dependent.
|
|   For the 'files' driver, it's a path to a writable directory.
|   WARNING: Only absolute paths are supported!
|
|   For the 'database' driver, it's a table name.
|   Please read up the manual for the format with other session drivers.
|
|   IMPORTANT: You are REQUIRED to set a valid save path!

depending on your environment use these:

mkdir /<path to your application directory>/sessions/

chmod 0700 /<path to your application directory>/sessions/

chown www-data /<path to your application directory>/sessions/

or

$config['sess_save_path'] = sys_get_temp_dir(); 
//php function which returns the directory path used for temporary files

more info on CI-sessions files driver

P.S. have a look at Session_files_driver.php (in your system/session/driver directory). There you see their use of mkdir in line 136: if ( ! mkdir($save_path, 0700, TRUE))=>>through error if dir is not writable)



来源:https://stackoverflow.com/questions/54543583/applying-codeigniter-3-to-a-new-domain-host-gives-mkdir-error-for-session-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!