Welcome Guest, Not a member yet? Register   Sign In
What causes duplicate session entry errors?
#1

I am encountering an issue in my CodeIgniter 4 application that utilizes a database for storing sessions. On production, some users are receiving the following error message:

"ERROR - 2023-02-25 15:19:48 --> mysqli_sql_exception: Duplicate entry 'ci_session:XXXXX' for key 'sessions.PRIMARY' in /var/www/html/system_4_2_11/Database/MySQLi/Connection.php:29"

This error seems to be unrelated to my code and is the complete chain. Here is the table structure of my sessions table:

"CREATE TABLE sessions(id varchar(60) NOT NULL, ip_address varchar(200) NOT NULL, timestamp int unsigned NOT NULL DEFAULT '0', data blob NOT NULL, PRIMARY KEY (id), KEY ci_sessions_timestamp (timestamp) ) ENGINE=InnoDB DEFAULT CHARSET=latin1"

I have considered the possibility that the issue could be caused by users attempting to log in on multiple tabs, but I have been unable to reproduce the error. Is it possible that the error is being triggered by a change in IP address, given that the platform is being used on a mobile network where IP addresses may change frequently?

I would appreciate any insights into what might be causing this error, aside from the obvious issue of attempting to re-enter a unique ID.
Reply
#2

I have the same issue. Since this question has not been answered here, I've created a bug report. https://github.com/codeigniter4/CodeIgni...ssues/7585
Reply
#3

(This post was last modified: 06-16-2023, 06:17 PM by kenjis.)

Can you show the $matchIP setting in Config\Session?
Reply
#4

The length of your session_id is wrong for MySQLi database
Code:
// wrong
sessions(id varchar(60) NOT NULL

// should be
sessions(id varchar(128) NOT NULL
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB