I'm developing a project with a small client area with the Silex framework. I want to store the session in database using the SessionServiceProvider
and PdoSessionHandler
but when I try to login with a test account the session is written in the database but the login is not done correctly and I get the login page in a loop. Also I'm getting the following error in the error log
Uncaught exception 'PDOException' with message 'SQLSTATE[22021]: Character not in repertoire: 7 ERROR: invalid byte sequence for encoding "UTF8"
The sessions table looks like this (got it from the Silex documentation page ):
CREATE TABLE sessions (
sess_id VARCHAR(255) NOT NULL,
sess_value TEXT NOT NULL,
sess_time INTEGER NOT NULL,
PRIMARY KEY(sess_id)
);
Anyone can help?
I found myself with the same error some time ago, looks like the silex documentation is incorrect for PostgreSQL, the sess_value
field should be a BYTEA
type field because the session data can contain characters that are not accepted in UTF-8 like the NULL character 0x00 .
Also as Silex uses the Symfony2 components for storing the session in database another field should be added, sess_lifetime that will contain the lifetime of the database session.
So the definition should be:
CREATE TABLE sessions (
sess_id VARCHAR(255) NOT NULL,
sess_value BYTEA NOT NULL,
sess_time INTEGER NOT NULL,
sess_lifetime INTEGER NOT NULL,
PRIMARY KEY(sess_id)
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.