http://www.cnblogs.com/liushannet/archive/2010/08/19/1803209.html Cookie使用:
<?php echo Cookie::salt("abc ","def ");#得到保存到客戶端的字符 #下面幾個不解釋~ echo Cookie::get("abc "); Cookie::set("abc ","def "); Cookie::delete ("abc ");
SESSION使用
類型有三個 (native,cookie,database)
默認是native(就是本地,PHP默認的)
其中database 配置
在APP的config裏建立一個session.php文件
內容爲:
<?php return array( 'database ' => array(
/** * Database settings for session storage. * * string group configuation group name * string table session table name * integer gc number of requests before gc is invoked * columns array custom column names */ 'group ' => 'default ', 'table ' => 'sessions ', 'gc ' => 500, 'columns ' => array( /** * session_id: session identifier * last_active: timestamp of the last activity * contents: serialized session data */ 'session_id ' => 'session_id ', 'last_active ' => 'last_active ', 'contents ' => 'contents ' ), ), );
建立數據表:(和你配置的數據庫配置有關係,下面描述)
CREATE TABLE `sessions` ( `session_id` VARCHAR( 24 ) NOT NULL, `last_active` INT UNSIGNED NOT NULL, `contents` TEXT NOT NULL, PRIMARY KEY ( `session_id` ), INDEX ( `last_active` ) ) ENGINE = MYISAM ;
其中cookie 配置
encrypted
配置
在相同目錄下建立encrypt.php
<? php return array ( "default "=>array ( "key "=>"dddd ",//你的密鑰 "mode "=>"ecb ",//加密方式,在PHP網站可以找到 "cipher "=>MCRYPT_RIJNDAEL_128,//加密方式,在PHP網站可以找到 ) );
如果使用native就最方便啦,不用配置
在這裏隨便提下數據庫配置吧
在同目錄下建立
database.php
<? php defined ('SYSPATH ') or die ('No direct access allowed. '); return array ( 'default ' => array ( 'type ' => 'pdo ', 'connection ' => array ( /** * The following options are available for PDO: * * string dsn Data Source Name * string username database username * string password database password * boolean persistent use persistent connections? */ 'dsn ' => 'mysql:host=localhost;dbname=**** ', 'username ' => 'root ', 'password ' => '****** ', 'persistent ' => FALSE, ), /** * The following extra options are available for PDO: * * string identifier set the escaping identifier */ 'table_prefix ' => 'ko_ ', 'charset ' => 'utf8 ', 'caching ' => FALSE, 'profiling ' => TRUE, ), );
以下是使用方式
<? php Session::instance("cookie ")->set("abc ","abcd "); echo Session::instance("cookie ")->get("abc "); Session::instance("cookie ")->delete("abc "); Session::instance("cookie ")->destroy();//清除SESSION
你可以把COOKIE去掉或者使用database試試,用database你會發現數據的sessions表會多一條記錄
本地方式的話可以留空 即爲:Session::instance();
修改Kohana_Session的$default爲你想要的默認方式,除了在控制器頭上設置不知道還有其他地方設置沒,有點不方便,
在不修改它源代碼的情況下~