facebook twitter hatena line email

Php/fuelphp/session

提供: 初心者エンジニアの簡易メモ
移動: 案内検索

session値追加・取得・削除

// 追加
$userid = 10;
Session::set('userid', $userid);
// 取得
$userid = Session::get('userid');
echo $userid; // 10
// 削除
Session::delete('userid');
echo $userid; // null

sessionのdriveをmemcachedに設定

  • fuel/app/config/session.php
return array(
 'driver'    => 'memcached',
 'memcached'    => array(
   'cookie_name'  => 'fuelmid',
   'servers'    => array(
           'default' => array('host' => '127.0.0.1', 'port' => 11211, 'weight' => 100)
         ),
       ),
);

その他オプション

  • fuel/app/config/session.php
return array(
 'auto_initialize'  => true,
 'driver'      => 'cookie',
 'match_ip'      => false,
 'match_ua'      => true,
 'cookie_domain'   => ,
 'cookie_path'    => '/',
 'cookie_http_only'  => null,
 'encrypt_cookie'  => true,
 'expire_on_close'  => false,
 'expiration_time'  => 7200,
 'rotation_time'    => 300,
 'flash_id'      => 'flash',
 'flash_auto_expire'  => true,
 'flash_expire_after_get' => true,
 'post_cookie_name'  => ,
 'header_header_name' => 'Session-Id',
 'enable_cookie'  => true,
 'cookie'    => array(
   'cookie_name'  => 'fuelcid',
         ),
 'file'      => array(
   'cookie_name'  => 'fuelfid',
   'path'      =>  '/tmp',
   'gc_probability'  =>  5
           ),
 'db'      => array(
   'cookie_name'  => 'fueldid',
   'database'    => null,
   'table'      => 'sessions',
   'gc_probability'  => 5
           ),
 'redis'      => array(
   'cookie_name'  => 'fuelrid',
   'database'    => 'default'
           )
);

session設定dump

var_dump(\Config::load('session'));