1 <?php defined('SYSPATH') OR die('No direct access allowed.');
3 * Session cookie driver.
5 * $Id: Cookie.php 3769 2008-12-15 00:48:56Z zombor $
9 * @copyright (c) 2007-2008 Kohana Team
10 * @license http://kohanaphp.com/license.html
12 class Session_Cookie_Driver implements Session_Driver {
14 protected $cookie_name;
15 protected $encrypt; // Library
17 public function __construct()
19 $this->cookie_name = Kohana::config('session.name').'_data';
21 if (Kohana::config('session.encryption'))
23 $this->encrypt = Encrypt::instance();
26 Kohana::log('debug', 'Session Cookie Driver Initialized');
29 public function open($path, $name)
34 public function close()
39 public function read($id)
41 $data = (string) cookie::get($this->cookie_name);
46 return empty($this->encrypt) ? base64_decode($data) : $this->encrypt->decode($data);
49 public function write($id, $data)
51 $data = empty($this->encrypt) ? base64_encode($data) : $this->encrypt->encode($data);
53 if (strlen($data) > 4048)
55 Kohana::log('error', 'Session ('.$id.') data exceeds the 4KB limit, ignoring write.');
59 return cookie::set($this->cookie_name, $data, Kohana::config('session.expiration'));
62 public function destroy($id)
64 return cookie::delete($this->cookie_name);
67 public function regenerate()
69 session_regenerate_id(TRUE);
75 public function gc($maxlifetime)
80 } // End Session Cookie Driver Class