问题
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