2

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;
moiamserru
  • 71
  • 8
  • 1
    please check this post: https://stackoverflow.com/questions/31042456/session-error-in-codeigniter – Vickel Feb 05 '19 at 21:55
  • also remember: If you add any space/line before php starting( – Vickel Feb 05 '19 at 23:33
  • and this: https://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php, hope this helps... – Vickel Feb 05 '19 at 23:35
  • Running through the backtrace (btw yes, it's ok to obscure the domain name) it seems either your session library is misconfigured or the directory where you intend to store the logs in doesn't exist or is not writable. Could you post your session configuration? – Javier Larroulet Feb 06 '19 at 02:20
  • @Vickel Your first suggestion solved my problem with mkdir()! Big thanks! But how do I mark your comment as the correct one? Or do you need to make a proper answer perhaps for that? – moiamserru Feb 06 '19 at 06:16

1 Answers1

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)

Vickel
  • 7,879
  • 6
  • 35
  • 56
  • I did not have $config['sess_save_path'] = sys_get_temp_dir(); set in my config file. After adding it it worked like it should! Thanks! – moiamserru Feb 06 '19 at 16:20