Home  >  Article  >  Backend Development  >  How to implement php's sso single sign-on, phpsso single sign-on_PHP tutorial

How to implement php's sso single sign-on, phpsso single sign-on_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:10:071100browse

php sso single sign-on implementation method, phpsso single sign-on

The example in this article describes the implementation method of PHP's SSO single sign-on. Share it with everyone for your reference. The specific analysis is as follows:

Here are some details:
1. Click Login to jump to the SSO login page and bring the callback address of the current application
2. After successful login, COOKIE is generated and passed to the callback address
3. The callback address receives the SSO COOKIE and sets it in the current domain, then jumps back to application 1 to complete the login
4. Then embed an iframe in the place where the application needs to log in to detect the login status in real time. The code is as follows:
index.php application page:

Copy code The code is as follows:
header('Content-Type:text/html; charset=utf-8');
$sso_address = 'http://XXXX.com/sso/login.php'; //The domain name of your SSO
$callback_address = 'http://'.$_SERVER['HTTP_HOST']
                    .str_replace('index.php','',$_SERVER['SCRIPT_NAME'])
.'Callback.php '; // callback address is used to set up cookie

if(isset($_COOKIE['sign'])){
exit("Welcome{$_COOKIE['sign']} Exit");
}else{
echo 'You are not logged in yet Click here to log in';
}
?>