2011-02-16 104 views
2

在同一個域上的兩個cakephp應用程序之間共享登錄信息有簡單的方法嗎?Cakephp在兩個應用程序之間共享驗證

基本上,MainApp有一個完整的用戶管理套件,我只想讓SecondaryApp知道訪問者是否登錄。

回答

5

確保兩個應用程序都配置爲以相同方式處理會話。換句話說,我們希望這兩個應用程序都從同一個cookie中讀取數據,並且我們需要兩個應用程序在該cookie中查找相同的位置。

//app\config\core.php for both apps 
Configure::write('Session.save', 'php'); //cookie path 
Configure::write('Session.cookie', 'app_name'); //cookie name 

在你MainApp,無論你做身份驗證,設置指示用戶會話變量已登錄。

$_SESSION['isLoggedIn'] = true; 

然後在SecondaryApp您可以閱讀會話變量並採取相應的行動。我想通常你會要求用戶登錄。

function beforefilter(){ 
    if(!$this->Session->read('isLoggedIn')) { 
     die("Please <a href='/users/login'>Login</a>"); 
    } 
} 
+0

當然!雖然有$ this-> Session->寫入?我沒有在cakephp書中看到一個 – Dave 2011-02-16 21:22:07

相關問題