PHP SSO Single Sign-on implementation method, Phpsso single Sign-on
This article describes the SSO single sign-on implementation method of PHP. Share to everyone for your reference. The specific analysis is as follows:
Here are a few details:
1. Click Login to jump to the SSO login page and bring the current app's callback address
2. Generate a cookie and pass the cookie to the callback address after successful login
3, callback address to receive SSO cookie and set in the current domain and then jump back to application 1 that completes the login
4. Embed an IFRAME where the application needs to log in to detect the login status in real time, with the following code:
index.php Application Page:
Copy CodeThe code is as follows: <?php
Header (' content-type:text/html; Charset=utf-8 ');
$sso _address = ' http://XXXX.com/sso/login.php '; The domain name where you are SSO
$callback _address = ' http://'. $_server[' Http_host '
. Str_replace (' index.php ', ' ', $_server[' script_name ')
.' Callback.php '; Callback address for callback settings cookie
if (isset ($_cookie[' sign ')) {
Exit ("Welcome you {$_cookie[' sign '}");
}else{
Echo ' You have not logged in point this login ';
}
?>
login.php SSO Login Page:
Copy CodeThe code is as follows: <?php
Header (' content-type:text/html; Charset=utf-8 ');
if (Isset ($_get[' logout ')) {
Setcookie (' sign ', ',-300);
unset ($_get[' logout ');
Header (' location:index.php ');
}
if (isset ($_post[' username ')) && isset ($_post[' password ']) {
Setcookie (' sign ', $_post[' username '],0, ');
Header ("Location:". $_post[' callback '). "? sign={$_post[' username '} ");
}
if (Emptyempty ($_cookie[' sign ')) {
?>
<?php
}else{
$query = Http_build_query ($_cookie);
echo "System detected that you are signed in {$_cookie[' sign '} authorized to Exit";
}
?>
The callback.php callback page is used to set the cross-domain cookie:
Copy CodeThe code is as follows: <?php
Header (' content-type:text/html; Charset=utf-8 ');
if (Emptyempty ($_get)) {
Exit (' You are not logged in ');
}else{
foreach ($_get as $key = = $val) {
Setcookie ($key, $val, 0, ");
}
Header ("location:index.php");
}
?>
Connect.php is used to detect the login status of the page, embedded in the page's IFRAME:
Copy CodeThe code is as follows: <?php
Header (' content-type:text/html; Charset=utf-8 ');
if (isset ($_cookie[' sign ')) {
$callback = UrlDecode ($_get[' callback '); unset ($_get[' callback ']);
$query = Http_build_query ($_cookie);
$callback = $callback. "? {$query} ";
}else{
Exit
}
?>
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/939404.html www.bkjia.com true http://www.bkjia.com/PHPjc/939404.html techarticle PHP SSO Single Sign-on implementation method, Phpsso Single Sign-on this article describes the PHP SSO single Sign-on implementation method. Share to everyone for your reference. The specific analysis is as follows: Here is a detailed talk ...