0

I'm a new user of CodeIgniter. I use CodeIgniter 3.1.3 and been struggling with this random-timed unknown mysterious fatal error since almost 2 weeks ago:

p.s. 1) I've been use CodeIgniter for about a month. 2) There is absolutely no error in my code!! So this is a pure system error, not syntax/runtime error.

Fatal error: Class CI_Session_database_driver contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (SessionHandlerInterface::read) in C:\xampp\htdocs\pokopoko\system\libraries\Session\drivers\Session_database_driver.php on line 49

A PHP Error was encountered

Severity: Error

Message: Class CI_Session_database_driver contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (SessionHandlerInterface::read)

Filename: drivers/Session_database_driver.php

Line Number: 49

Backtrace:

Error text is not always the same! Sometimes:

Filename: drivers/Session_files_driver.php

Or

Filename: drivers/Session_database_driver.php

Or

Filename: Session/Session_driver.php

Or

Filename: core/Input.php

Or even

Filename: Unknown

This error happen at random time, when I reload my website, or even when my website still opened (idle) in browser without I doing anything, my ajax suddenly not work! This happen not only in certain browser! I'm absolutely haven't changed/modified/opened any of CodeIgniter's system files!!

I have tried:

  1. Restarted my apache like suggested here: CodeIgniter Database Session Error. This work but only temporary till this random-timed unknown mysterious fatal error happen again.
  2. Re-extract fresh downloaded CodeIgniter-3.1.3.zip to my htdocs. Move my project. Still happen!
  3. Reinstall my XAMPP (the latest version). This error not appear ... until few hours later, no difference with before.

Few screenshots:

enter image description here

enter image description here

enter image description here

enter image description here

What is this? What's the solution? Help me.

Update:

This is my autoload.php & config.php content:

my autoload.php:

$autoload['packages'] = array();
$autoload['libraries'] = array('database','session'); //I set this
$autoload['drivers'] = array();
$autoload['helper'] = array('url','array'); //I set this
$autoload['config'] = array();
$autoload['language'] = array();
$autoload['model'] = array();

my config.php:

$config['base_url'] = 'http://localhost/pokopoko/'; //I set this
$config['index_page'] = 'index.php';
$config['uri_protocol'] = 'REQUEST_URI';
$config['url_suffix'] = '';
$config['language'] = 'english';
$config['charset'] = 'UTF-8';
$config['enable_hooks'] = FALSE;
$config['subclass_prefix'] = 'MY_';
$config['composer_autoload'] = FALSE;
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';

$config['enable_query_strings'] = FALSE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
$config['directory_trigger'] = 'd';

$config['allow_get_array'] = TRUE;
$config['log_threshold'] = 0;
$config['log_path'] = '';
$config['log_file_extension'] = '';
$config['log_file_permissions'] = 0644;
$config['log_date_format'] = 'Y-m-d H:i:s';
$config['error_views_path'] = '';
$config['cache_path'] = '';
$config['cache_query_string'] = FALSE;
$config['encryption_key'] = '';

$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;

$config['cookie_prefix']    = '';
$config['cookie_domain']    = '';
$config['cookie_path']      = '/';
$config['cookie_secure']    = FALSE;
$config['cookie_httponly']  = FALSE;

$config['standardize_newlines'] = FALSE;

$config['global_xss_filtering'] = FALSE;

$config['csrf_protection'] = FALSE;
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
$config['csrf_expire'] = 7200;
$config['csrf_regenerate'] = TRUE;
$config['csrf_exclude_uris'] = array();

$config['compress_output'] = FALSE;

$config['time_reference'] = 'local';

$config['rewrite_short_tags'] = FALSE;

$config['proxy_ips'] = '';

Update #2:

I tried @Fairy Dancer's solution. Work about 1 hour, but then this error reappear (Error information changed, but still the same Session_database_driver.php on line 49)

enter image description here

Update #3:

Yesterday @Rahi and I together has suspected that it maybe a bug between CodeIgniter 3 with PHP >7. There's also other developer with same environment/combination experiencing this issue, like here: https://forum.codeigniter.com/thread-66544.html. But I can't downgrade my PHP because I'm using many PHP 7 new shorthands like ??. If this true, maybe I'll wait until there's another solution, or until CI have newer version with this bug fixed.

Community
  • 1
  • 1
Taufik Nur Rahmanda
  • 1,862
  • 2
  • 20
  • 36

4 Answers4

1

Change your session

$config['sess_driver'] = 'files'; to $config['sess_driver'] = 'database';

and execute the sql code into your database table

CREATE TABLE IF NOT EXISTS `ci_sessions` (
    `id` varchar(128) NOT NULL,
    `ip_address` varchar(45) NOT NULL,
    `timestamp` int(10) unsigned DEFAULT 0 NOT NULL,
    `data` blob NOT NULL, KEY `ci_sessions_timestamp` (`timestamp`));

Make sure you configure your database in database.php file.

Let me know if this not works

Kirk Beard
  • 9,569
  • 12
  • 43
  • 47
  • Thanks a lot for the answer. Let me try this! :) I can't tell now it work or no, because the error appear suddenly in random time, so I don't know if maybe few hours later error still appear when I refresh my page. But let see. Hope this really work. – Taufik Nur Rahmanda Feb 27 '17 at 12:38
  • 1
    Codeigniter use to create a session file in your session temp directors with timestamp. Every 2 hrs it used to recreate the instance. Sometimes it show this error while handling the session files. I faced this error two years before for the website called www.iynar.com and it solved for me by using the above method. For creating session files, I format my PC and install wamp server 2.5 and its start working fine. –  Feb 27 '17 at 12:45
  • Thanks for the explanation :D Feel more relieved now. – Taufik Nur Rahmanda Feb 27 '17 at 12:55
  • Can you please replace your system files in codeigniter with latest version again –  Feb 27 '17 at 15:01
  • Okay I'll try. :) – Taufik Nur Rahmanda Feb 27 '17 at 15:38
  • may I asking which PHP version do you use? 7 or 5? I've suspected that this is might be the unsolved bug of combination between CI 3.1.3 and PHP >7. Btw I've deleted & recopy my system `folder`. Apparently error (still) not appear till now. – Taufik Nur Rahmanda Feb 27 '17 at 23:49
  • Sorry for late response. I'm using PHP 5.5.12 Wamp Server 2.5 Apache version 1.4.9 and MySql 5.6.17 –  Feb 28 '17 at 08:11
0

Replace

$config['sess_driver'] = 'files'; 

with

$config['sess_driver'] = 'database';
Rahi
  • 1,435
  • 1
  • 12
  • 20
  • What version of PHP are you running? – Rahi Feb 27 '17 at 15:39
  • almost recent version, 7.1.1 – Taufik Nur Rahmanda Feb 27 '17 at 15:45
  • I am hoping you haven't made any changes in CI core files. Did you? – Rahi Feb 27 '17 at 15:46
  • Of course I'm never touch any single file in there. I'm only use CI about a month, only changed general configs in application folder such as `database`, `autoload`, `config` (for basepath), and `route` (for default controller). – Taufik Nur Rahmanda Feb 27 '17 at 15:52
  • 1
    This might sound little regressive but can you downgrade your XAMMP so that to have lower PHP version (May be 5.6)? This issue seems to be reported by different developer on PHP 7. – Rahi Feb 27 '17 at 16:09
  • Actually I had thought about that too! I've also suspected that it might be the bug of combination between CI and PHP 7. I've searched & found there are other people asking this same problem, but I found only several, and there's (still) no any permanent solution. Might be because there's no too many people use combination of CI 3.1.3 and PHP 7 (?) – Taufik Nur Rahmanda Feb 27 '17 at 23:43
0

I meet the same problem when i use PHP 7.1

But if i downgrade to PHP 7.0 the error is gone...

Just try to use PHP 7.0 and no change in Codeigniter at all.

-2

Sometimes it will happen, just restart your server either it will be apache or other than apache, after restarting the server the error will be gone..... depends the the type of the error occurred while working. If the error is occurred automatically while working than it will simply removed by just restarting the server. In my case it will gone by just stopping and starting my local xampp server.

Krishna
  • 1
  • 1