ticket共有式単点ログイン

11477 ワード

フローチャート
ticket共享式单点登录_第1张图片
サーバの検証
table('user')->where(['account'=>$account, 'password'=>md5($password)])->find();
            if(empty($user)){
                $_SESSION['error'] = '       ';
                require 'sso.html';
                die;
            }

            unset($_SESSION['error']);
            $login_a_url = "http://a.com/index.php?action=login&ticket=".$user['ticket'];
            $login_b_url = "http://b.com/index.php?action=login&ticket=".$user['ticket'];
            $res1 = file_get_content($login_a_url );
            $res2 = file_get_content($login_b_url );
            if($res1 == $res2 == 'success'){
            	header("location:".$server."?action=login&ticket=".$user['ticket']);
            }else{
            	$_SESSION['error'] = '    ';
				require 'sso.html';
			}

        }else{
            $server = isset($_GET['server'])?trim($_GET['server']):die('    ');
            require 'sso.html';
        }
    }

    /**
     *      
     */
    public function logout()
    {
        $url1 = 'http://a.com/index.php?action=logout&server='.$_GET['server'];
        header('Location:'.$url1);
    }

    /**
     *    ticket   
     */
    public function verify()
    {
        $ticket = trim($_GET['ticket']);

        //  ticket   
        if($ticket){
            $db = Db::getInstance();
            $user = $db->table('user')->where(['ticket'=>$ticket])->find();
            if($user){
                echo 'success';
            }else{
                echo "fail";
            }
            die;
        }
        echo 'fail';
        die;
    }

    /**
     *   ticket      
     */
    public function user()
    {
        $ticket = trim($_GET['ticket']);
        $db = Db::getInstance();
        $user = $db->table('user')->where(['ticket'=>$ticket])->find();

        echo json_encode($user);
    }

}

$action = isset($_GET['action'])?trim($_GET['action']):'login';

(new Passport())->$action();


htmlフォーム



    
        


    
error:

サイトA
_jump($msg,$url);
            }

        }else{
            $msg = "     ";
            $url = "http://passport.com/index.php?action=login&server=http://a.com/index.php";
            $this->_jump($msg,$url);
        }

    }

    /**
     *       ,        
     */
    public function index()
    {
        $ticket = @$_GET['ticket'];
        if($ticket && !isset($_SESSION['user'])){
            $verify_url = 'http://passport.com/index.php?action=verify&ticket='.$ticket;
            if(file_get_contents($verify_url)=='success') {
                //       
                $get_user_info_url = 'http://passport.com/index.php?action=user&ticket=' . $ticket;
                $user = file_get_contents($get_user_info_url);
                $_SESSION['user'] = json_decode($user, true);
            }else{
                $msg = "     ";
                $url = "http://passport.com/index.php?action=login&server=http://a.com/index.php";
                $this->_jump($msg,$url);
            }
        }

        if($_SESSION['user']) {
            $ticket = $_SESSION['user']['ticket'];
            echo "";
            echo "A       
"; echo " B"; }else{ $msg = " "; $url = "http://passport.com/index.php?action=login&server=http://a.com/index.php"; $this->_jump($msg,$url); } } public function logout() { session_destroy(); $server = $_GET['server']; $url1 = 'http://b.com/index.php?action=logout&server='.$server; header('Location:'.$url1); } /** * * @param $msg * @param $url */ private function _jump($msg, $url) { ob_clean(); echo "{$msg}3 。"; echo " var time = document.getElementById('time'); setInterval(function(){ time.innerHTML = parseInt(time.innerHTML) -1; if(time.innerHTML<1){ location.href='$url'}; },1000);"; die; } } $action = isset($_GET['action'])?trim($_GET['action']):'index'; (new A())->$action();

サイトB
_jump($msg,$url);
            }

        }else{
            $msg = "     ";
            $url = "http://passport.com/index.php?action=login&server=http://b.com/index.php";
            $this->_jump($msg,$url);
        }

    }

    /**
     *       ,        
     */
    public function index()
    {
        $ticket = @$_GET['ticket'];
        if($ticket && !isset($_SESSION['user'])){
            $verify_url = 'http://passport.com/index.php?action=verify&ticket=' . $ticket;
            if(file_get_contents($verify_url)=='success') {
                //       
                $get_user_info_url = 'http://passport.com/index.php?action=user&ticket=' . $ticket;
                $user = file_get_contents($get_user_info_url);
                $_SESSION['user'] = json_decode($user, true);
            }else{
                $msg = "     ";
                $url = "http://passport.com/index.php?action=login&server=http://b.com/index.php";
                $this->_jump($msg,$url);
            }
        }

        if($_SESSION['user']) {
            $ticket = $_SESSION['user']['ticket'];
            echo "";
            echo "B       
"; echo " A"; }else{ $msg = " "; $url = "http://passport.com/index.php?action=login&server=http://b.com/index.php"; $this->_jump($msg,$url); } } public function logout() { session_destroy(); $server = $_GET['server']; $url2 = 'http://passport.com/index.php?action=login&server='.$server; header('Location:'.$url2); } /** * * @param $msg * @param $url */ private function _jump($msg, $url) { ob_clean(); echo "{$msg}3 。"; echo " var time = document.getElementById('time'); setInterval(function(){ time.innerHTML = parseInt(time.innerHTML) -1; if(time.innerHTML<1){ location.href='$url'}; },1000);"; die; } } $action = isset($_GET['action'])?trim($_GET['action']):'index'; (new B())->$action();