Cakephp sharing auth between two applications

て烟熏妆下的殇ゞ 提交于 2020-01-24 16:39:05

问题


Is there an easy way to share login information between two cakephp apps on the same domain?

Basically, MainApp has a full fledged user management suite, and I just want SecondaryApp to know if a visitor is logged in or not.


回答1:


Make sure both applications are configured to handle the session the same way. In other words, we want both apps to read from the same cookie and we need both apps to look in the same location for that cookie.

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

In your MainApp, wherever you do the Authentication, set a session variable indicating the user has logged in.

$_SESSION['isLoggedIn'] = true;

Then in SecondaryApp you can read the session variables and act accordingly. I suppose typically you would ask to user to login.

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


来源:https://stackoverflow.com/questions/5022040/cakephp-sharing-auth-between-two-applications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!