Welcome Guest, Not a member yet? Register   Sign In
[Solved] duplicate database entry with database session driver

(This post was last modified: 02-11-2015, 05:02 AM by betz0r.)


i am experiencing some troubles with the database session driver:

Error Number: 1062

Duplicate entry 'SESSIONIDKEYREMOVED' for key 'PRIMARY'

INSERT INTO `ci_sessions` (`id`, `ip_address`, `timestamp`, `data`) VALUES ('SESSIONIDKEYREMOVED', 'IPADDRESSREMOVED', 1423636803, '')

Filename: libraries/Session/drivers/Session_database_driver.php

Line Number: 216

How can i "catch" this error without modifing the core/session package but in the application code? I don't know where this duplicate entry is coming from and why it's happening, but it brakes the whole website...

You've got sess_match_ip turned on, but you've kept only the 'session_id' field as primary key and you're visiting the site from another IP address ...

Thanks a lot, i read about the primary key earlier but forgot indeed to change it in my database.
This is solved then!

Keep on the good work ;-)

I"m running into this error a lot and I think it's setup right.


DROP TABLE `ci_sessions`;
   CREATE TABLE IF NOT EXISTS `ci_sessions` (
       `id` varchar(40) NOT NULL,
       `ip_address` varchar(45) NOT NULL,
       `timestamp` int(10) unsigned DEFAULT 0 NOT NULL,
       `data` blob NOT NULL,
       PRIMARY KEY (id),
       KEY `ci_sessions_timestamp` (`timestamp`)
   ALTER TABLE ci_sessions ADD CONSTRAINT ci_sessions_id_ip UNIQUE (id, ip_address);

My session config (I needed a clause for when running tests):

   $config['sess_driver'] = (defined('CODECEPTION_TEST') ? 'files' : 'database');
   $config['sess_cookie_name'] = 'cisession';
   $config['sess_expiration'] = 7200;
   $config['sess_save_path'] = ($config['sess_driver'] === 'files' ? dirname(APPPATH) . '/sessions/' : 'ci_sessions');
   $config['sess_match_ip'] = true;
   $config['sess_time_to_update'] = $config['sess_expiration'];

The error I get:

   error - 2015-06-17 21:48:46 --> Query error: Duplicate entry 'fa431390cb8caae340986a0dbc751e2890890788' for key 'PRIMARY' - Invalid query: INSERT INTO `ci_sessions` (`id`, `ip_address`, `timestamp`, `data`) VALUES ('fa431390cb8caae340986a0dbc751e2890890788', '', 1434595726, '')

Theme © iAndrew 2016 - Forum software by © MyBB