本文章介紹了一個關於在php中實現自動登錄與自動驗證的實現代碼,有需要的朋友可以參考一下。 代碼如下 復制代碼
$urls = parse_url($db_bbsurl);
$domain = $urls['host'];
include_once (R_P .'require/admvclient.php');
$adm_oem= new Cnzz_Adm_Oem();
//判斷config文件是否存在用戶密碼
pwCache::getData(D_P . "data/bbscache/adm_config.php");//用戶名密碼 配置文件
if (isset($adm_user) && isset($adm_pwd)) {
$request = array("adm_user"=>$adm_user,"adm_pwd"=>$adm_pwd,'cms'=>'pw');
$token = $adm_oem->get_appkey_once($request);
if ($token<0){
if($token==-1){
adminmsg('傳遞參數為空或傳遞參數非數字');
}else if($token==-2){
adminmsg('傳遞參數password錯誤');
}
}else{
$apikey = $token['adm_key'];
}
}else{
$Key = md5($domain.'KclGiq7H');
$request = array('cms'=>'pw','domain'=>$domain,'key'=>$Key);
$token = $adm_oem->reg_user_once($request);
if ($token<0){//異常
if($token==-1){
adminmsg('key有誤');
} else if($token==-2){
adminmsg('域名長度有誤(1~64)');
} elseif($token==-3){
adminmsg('域名輸入有誤(比如輸入漢字)');
} elseif($token==-4){
adminmsg('域名插入數據庫有誤');
} elseif($token==-5){
adminmsg('IP用戶調用頁面超過閥值,閥值暫定為10');
}
} elseif (is_array($token) && isset($token)){
$adm_user = $token['adm_user'];
$adm_pwd = $token['adm_pwd'];
$apikey = $token['adm_key'];
pwCache::setData(D_P.'data/bbscache/adm_config.php',"<?phprn$adm_user=".$adm_user.";rn$adm_pwd=".$adm_pwd."rn?>");
}
}