手记

web网站token简单实现,用于接口

tp框架:    

private function checkAuth()

    { 
        $password = C('SERVIE_PASSWOED');//网站的密钥; 

        if (!empty($_GET)) { 
            ksort($_GET); 
            $param = ''; 
            foreach ($_GET as $key => $value) { 
                if ($key != 'token') { 
                    $param .= $value; 
                } 
            } 

            $param.= $password; 

            if (md5($param) != $_GET['token']) { 
                return false; 
            } else { 
                if ((time() - $_GET['time']) > 60) { 
                    return false; 
                } 
            } 
        } 

        return true; 
    }
0人推荐
随时随地看视频
慕课网APP