|
<? Php
// Index. php application page
Header ('content-Type: text/html; charset = UTF-8 ');
$ Sso_address = 'HTTP: // 2spaoku.com/sso/login.php'; // your SSO Domain Name
$ Callback_address = 'HTTP: // '. $ _ SERVER ['HTTP _ host']
. Str_replace ('index. php', '', $ _ SERVER ['script _ name'])
. 'Callback. php'; // The callback address is used to set the cookie for callback.
If (isset ($ _ COOKIE ['sign']) {
Exit ("Welcome to {$ _ COOKIE ['sign']} <a href =" login. php? Logout "> exit </a> ");
} Else {
Echo 'Have you logged on to <a href = "'. $ sso_address .'? Callback = '. $ callback_address.' "> click here to log on </a> ';
}
?>
<Iframe src = "<? Php echo $ sso_address?>? Callback = <? Php echo $ callback_address?> "Frameborder =" 0 "width =" 0 "height =" 0 "> </iframe>
<? Php
// Login. php SSO logon page
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 (empty ($ _ COOKIE ['sign']) {
?>
<Form method = "post">
<P> User name: <input type = "text" name = "username"/> </p>
<P> password: <input type = "password" name = "password"/> </p>
<Input type = "hidden" name = "callback" value = "<? Php echo $ _ GET ['callback'];?> "/>
<Input type = "submit" value = "login"/>
</Form>
<? Php
} Else {
$ Query = http_build_query ($ _ COOKIE );
Echo "the system has detected that you have logged on to {$ _ COOKIE ['sign']} <a href =" {$ _ GET ['callback']}? {$ Query} "> authorization </a> <a href = "? Logout "> exit </a> ";
}
?>
<? Php
// The callback. php callback page is used to set cross-domain cookies.
Header ('content-Type: text/html; charset = UTF-8 ');
If (empty ($ _ GET )){
Exit ('you have not logged on to it ');
} Else {
Foreach ($ _ GET as $ key => $ val ){
Setcookie ($ key, $ val, 0 ,'');
}
Header ("location: index. php ");
}
?>
<? Php
// Connect. php is used to check the login status page, embedded in the iframe of the page
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;
}
?>
<Html> <script type = "text/javascript"> top. location. href = "<? Php echo $ callback;?> "; </Script>
|