LoginSignup
21
24

More than 5 years have passed since last update.

CakePHPのセッション管理をDBに変更する

Posted at

CakePHPのセッション管理をDBに変更する方法をメモします。

core.phpの190行目以下を下記のように変更します。

core.php
    Configure::write('Session', array(
        'defaults' => 'database',
        'cookie' => 'SID',
        //セッションの保持時間(秒数)
        'timeout' => 86400,
    ));

データベースにテーブルを作成します。

session.sql
CREATE TABLE IF NOT EXISTS `cake_sessions` (
    `id` varchar(255) NOT NULL DEFAULT '',
    `data` text NOT NULL,
    `expires` int(11) DEFAULT NULL,
    PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

以上です。

21
24
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
24