Initial Kohana install
[speedfreak] / Server / system / libraries / drivers / Session / Cookie.php
1 <?php defined('SYSPATH') OR die('No direct access allowed.');
2 /**
3  * Session cookie driver.
4  *
5  * $Id: Cookie.php 3769 2008-12-15 00:48:56Z zombor $
6  *
7  * @package    Core
8  * @author     Kohana Team
9  * @copyright  (c) 2007-2008 Kohana Team
10  * @license    http://kohanaphp.com/license.html
11  */
12 class Session_Cookie_Driver implements Session_Driver {
13
14         protected $cookie_name;
15         protected $encrypt; // Library
16
17         public function __construct()
18         {
19                 $this->cookie_name = Kohana::config('session.name').'_data';
20
21                 if (Kohana::config('session.encryption'))
22                 {
23                         $this->encrypt = Encrypt::instance();
24                 }
25
26                 Kohana::log('debug', 'Session Cookie Driver Initialized');
27         }
28
29         public function open($path, $name)
30         {
31                 return TRUE;
32         }
33
34         public function close()
35         {
36                 return TRUE;
37         }
38
39         public function read($id)
40         {
41                 $data = (string) cookie::get($this->cookie_name);
42
43                 if ($data == '')
44                         return $data;
45
46                 return empty($this->encrypt) ? base64_decode($data) : $this->encrypt->decode($data);
47         }
48
49         public function write($id, $data)
50         {
51                 $data = empty($this->encrypt) ? base64_encode($data) : $this->encrypt->encode($data);
52
53                 if (strlen($data) > 4048)
54                 {
55                         Kohana::log('error', 'Session ('.$id.') data exceeds the 4KB limit, ignoring write.');
56                         return FALSE;
57                 }
58
59                 return cookie::set($this->cookie_name, $data, Kohana::config('session.expiration'));
60         }
61
62         public function destroy($id)
63         {
64                 return cookie::delete($this->cookie_name);
65         }
66
67         public function regenerate()
68         {
69                 session_regenerate_id(TRUE);
70
71                 // Return new id
72                 return session_id();
73         }
74
75         public function gc($maxlifetime)
76         {
77                 return TRUE;
78         }
79
80 } // End Session Cookie Driver Class