php自動(dòng)注冊登錄驗(yàn)證機(jī)制實(shí)現(xiàn)代碼
Jun 13, 2016 pm 12:03 PM
背景:
在phpwind站點(diǎn)后臺(tái)添加一個(gè)名為“廣告管家”(廣告管家為CNZZ的一款廣告投放的應(yīng)用)的應(yīng)用,整個(gè)“廣告管家”的應(yīng)用是通過iframe載入,載入的具體內(nèi)容根據(jù)不同站點(diǎn)顯示針對該站點(diǎn)的具體內(nèi)容,為了提高易用性,有以下的兩點(diǎn)要求:
1、首次進(jìn)入“廣告管家”頁面自動(dòng)注冊CNZZ賬戶
2、以后每次進(jìn)入“廣告管家”頁面默認(rèn)為首次注冊的CNZZ賬戶
設(shè)計(jì):
1、嘗試載入用戶帳號和密碼信息,此信息保存在數(shù)據(jù)庫或是文本緩存中
2、當(dāng)存在用戶名和密碼的情況下向cnzz發(fā)送一個(gè)請求用來獲取Token,將此Token值加入到iframe的地址中,如此就能載入針對該用戶的頁面
3、當(dāng)不存在用戶名和敏嗎的情況下待用cnzz的注冊接口,注冊成功后返回token,也同樣將此Token作為iframe地址的一部分用來載入頁面
4、Token值有效期只有一次,即使被截取了也能保證安全性
代碼:
復(fù)制代碼 代碼如下:
$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 ($tokenif($token==-1){
adminmsg('傳遞參數(shù)為空或傳遞參數(shù)非數(shù)字');
}else if($token==-2){
adminmsg('傳遞參數(shù)password錯(cuò)誤');
}
}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 ($tokenif($token==-1){
adminmsg('key有誤');
} else if($token==-2){
adminmsg('域名長度有誤(1~64)');
} elseif($token==-3){
adminmsg('域名輸入有誤(比如輸入漢字)');
} elseif($token==-4){
adminmsg('域名插入數(shù)據(jù)庫有誤');
} elseif($token==-5){
adminmsg('IP用戶調(diào)用頁面超過閥值,閥值暫定為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',"");
}
}

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Comments cannot be careless because they want to explain the reasons for the existence of the code rather than the functions, such as compatibility with old interfaces or third-party restrictions, otherwise people who read the code can only rely on guessing. The areas that must be commented include complex conditional judgments, special error handling logic, and temporary bypass restrictions. A more practical way to write comments is to select single-line comments or block comments based on the scene. Use document block comments to explain parameters and return values at the beginning of functions, classes, and files, and keep comments updated. For complex logic, you can add a line to the previous one to summarize the overall intention. At the same time, do not use comments to seal code, but use version control tools.

PHPblockcommentsareusefulforwritingmulti-lineexplanations,temporarilydisablingcode,andgeneratingdocumentation.Theyshouldnotbenestedorleftunclosed.BlockcommentshelpindocumentingfunctionswithPHPDoc,whichtoolslikePhpStormuseforauto-completionanderrorche

The key to writing good comments is to explain "why" rather than just "what was done" to improve the readability of the code. 1. Comments should explain logical reasons, such as considerations behind value selection or processing; 2. Use paragraph annotations for complex logic to summarize the overall idea of functions or algorithms; 3. Regularly maintain comments to ensure consistency with the code, avoid misleading, and delete outdated content if necessary; 4. Synchronously check comments when reviewing the code, and record public logic through documents to reduce the burden of code comments.

TolearnPHPeffectively,startbysettingupalocalserverenvironmentusingtoolslikeXAMPPandacodeeditorlikeVSCode.1)InstallXAMPPforApache,MySQL,andPHP.2)Useacodeeditorforsyntaxsupport.3)TestyoursetupwithasimplePHPfile.Next,learnPHPbasicsincludingvariables,ech

The first step is to select the integrated environment package XAMPP or MAMP to build a local server; the second step is to select the appropriate PHP version according to the project needs and configure multiple version switching; the third step is to select VSCode or PhpStorm as the editor and debug with Xdebug; in addition, you need to install Composer, PHP_CodeSniffer, PHPUnit and other tools to assist in development.

The key to setting up PHP is to clarify the installation method, configure php.ini, connect to the web server and enable necessary extensions. 1. Install PHP: Use apt for Linux, Homebrew for Mac, and XAMPP recommended for Windows; 2. Configure php.ini: Adjust error reports, upload restrictions, etc. and restart the server; 3. Use web server: Apache uses mod_php, Nginx uses PHP-FPM; 4. Install commonly used extensions: such as mysqli, json, mbstring, etc. to support full functions.

To learn PHP, you need to master variables and data types, control structures, function definitions and call specifications, and avoid common syntax errors. 1. Variables start with $, case sensitive, and types include strings, integers, booleans, etc.; 2. The control structure supports if/else/loop, and the template can use colon syntax instead of curly braces, foreach can handle arrays conveniently; 3. Functions are defined with function, supporting default parameters and variable parameters; 4. Common errors include missing semicolons, confusion == and ===, splicing characters errors, and improper use of array subscripts.

The key to writing PHP comments is clear, useful and concise. 1. Comments should explain the intention behind the code rather than just describing the code itself, such as explaining the logical purpose of complex conditional judgments; 2. Add comments to key scenarios such as magic values, old code compatibility, API interfaces, etc. to improve readability; 3. Avoid duplicate code content, keep it concise and specific, and use standard formats such as PHPDoc; 4. Comments should be updated synchronously with the code to ensure accuracy. Good comments should be thought from the perspective of others, reduce the cost of understanding, and become a code understanding navigation device.
