Reputation: 1913
I wonder why each refresh of the page of the website I'm writing, or moving between different pages, creates new session record (I'm storing them in DB instead of using standard solution). In other words, each single click (I'm not using JS / AJAX) creates new record / new session.
Here's my configuration of sessions in config file:
session:
lifetime: 7200
domain: MY_SERVER
handler_id: session.handler.pdo
parameters:
pdo.db_options:
db_table: session
db_id_col: session_id
db_data_col: session_value
db_time_col: session_time
services:
pdo:
class: PDO
arguments:
dsn: HOST
user: USER
password: PSWD
session.handler.pdo:
class: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler
arguments: [@pdo, %pdo.db_options%]
I tried to use:
auto_start: false
But I'm getting then the following error from Symfony2.1:
The auto_start setting is deprecated. Just remove it from your configuration file.
So what should I do to have normal sessions?
UPDATE I also used the following:
arguments:
- "mysql:host=%database_host%;dbname=%database_name%"
- %database_user%
- %database_password%
that is, my basic Data Base settings for whole project (stored in parameters.yml).
Upvotes: 0
Views: 743
Reputation: 622
This can happen if you do not have session_id set as primary key. Create the session table using (from the documentation, MySQL):
CREATE TABLE `session` (
`session_id` varchar(255) NOT NULL,
`session_value` text NOT NULL,
`session_time` int(11) NOT NULL,
PRIMARY KEY (`session_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
For other databases, see How to use PdoSessionHandler to store Sessions in the Database
Upvotes: 1