1. 程式人生 > >Thinkphp設定session共享使用 redis實現

Thinkphp設定session共享使用 redis實現

首先在Thinkphp 配置項裡面設定

'SESSION_OPTIONS'=>array("session.save_handler"=>"redis",
"session.save_path"=>"tcp://localhost:6379"//redis主伺服器
),
測試:
public function session_test(){    session_start();
    header("Content-type:text/html;charset=utf-8");
if(isset($_SESSION['test'])){$_SESSION['test'] = 
$_SESSION['test'] + 1; }else{$_SESSION['test'] = 1; } print_r($_SESSION); print_r(session_id()); }

public function session_test2(){    ini_set("session.save_handler", "redis");
    ini_set("session.save_path", "tcp://localhost:6380");//redis從伺服器
    session_start();
    print_r($_SESSION);
    print_r
(session_id()); }