Home Backend Development PHP Tutorial php自动注册登录验证机制实现代码_PHP

php自动注册登录验证机制实现代码_PHP

Jun 01, 2016 pm 12:14 PM
Login authentication

背景:

在phpwind站点后台添加一个名为“广告管家”(广告管家为CNZZ的一款广告投放的应用)的应用,整个“广告管家”的应用是通过iframe载入,载入的具体内容根据不同站点显示针对该站点的具体内容,为了提高易用性,有以下的两点要求:
1、首次进入“广告管家”页面自动注册CNZZ账户
2、以后每次进入“广告管家”页面默认为首次注册的CNZZ账户


设计:


1、尝试载入用户帐号和密码信息,此信息保存在数据库或是文本缓存中
2、当存在用户名和密码的情况下向cnzz发送一个请求用来获取Token,将此Token值加入到iframe的地址中,如此就能载入针对该用户的页面
3、当不存在用户名和敏吗的情况下待用cnzz的注册接口,注册成功后返回token,也同样将此Token作为iframe地址的一部分用来载入页面
4、Token值有效期只有一次,即使被截取了也能保证安全性
代码:
复制代码 代码如下:
$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('传递参数为空或传递参数非数字');
}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 ($tokenif($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',"");
}
}

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Quick Start: Use Go language functions to implement simple login verification functions Quick Start: Use Go language functions to implement simple login verification functions Jul 29, 2023 pm 05:33 PM

Quick Start: Use Go language functions to implement simple login verification function In web application development, user login is a very common function. This article will introduce how to use Go language functions to implement a simple login verification function to help you quickly get started with web development in Go language. We will use the Go language's net/http package to create an HTTP server and listen for user requests. Use Go language functions and simple logical judgments to implement user login verification functions. First, create a new Go file,

Python implements page login verification and verification code identification function analysis for headless browser collection applications Python implements page login verification and verification code identification function analysis for headless browser collection applications Aug 08, 2023 am 10:49 AM

Python implements page login verification and verification code identification function analysis for headless browser collection applications. With the continuous development of Internet technology, more and more applications use page login verification and verification code identification functions to improve security. When crawling and collecting data from these applications, we also need to solve these problems. This article will introduce how to use Python to implement a headless browser to handle page login verification and verification code identification for smooth data collection. 1. Introduction to headless browsers Headless browsers

How to cancel Bilibili login verification? Tutorial on turning off login verification on Bilibili How to cancel Bilibili login verification? Tutorial on turning off login verification on Bilibili Mar 15, 2024 pm 04:58 PM

Bilibili is currently the most popular barrage video sharing website among young people. Here, we can find a lot of content, including learning, entertainment, games, food, etc. It covers all aspects of content and provides users with Come conveniently. So does anyone know how to turn off the Bilibili login verification code? How to turn off the Bilibili login verification code 1. Open Bilibili, click on the avatar in the upper left corner, scroll down to find settings, and click to enter. 2. Click to enter Security Privacy. 3. Click to log in to device management. 4. Turn off the login device management switch. 5. Click Verify to close, then verify with your mobile phone and enter the verification code to close successfully. Features of the software: Ghost Zone: Two- and three-dimensional videos of ghosts and beasts, endless imaginative holes, impossible to prevent

How to implement user login function in PHP How to implement user login function in PHP Jun 11, 2023 am 11:54 AM

With the continuous development of the Internet, the user login function has become an essential part of many websites. As a programming language widely used in web development, PHP can also implement user login functions by writing code. In this article, we will detail how to implement user login functionality in PHP. Prerequisites Before starting to write the user login function, we need to prepare the following prerequisites: PHP environment: Make sure you have installed the PHP environment and know how to run PHP code locally. Database: login function

Mastering PHP and PHPMAILER: How to implement login verification function for sending emails? Mastering PHP and PHPMAILER: How to implement login verification function for sending emails? Jul 22, 2023 am 11:16 AM

Master PHP and PHPMailer: How to implement login verification function for email sending? Introduction: When developing websites and applications, you often need to send verification links via email, notify users, and other functions. PHP and PHPMailer are commonly used tools by developers. Through them, we can easily implement the login verification function of sending emails. This article will lead readers to learn in detail how to use PHP and PHPMailer, and how to implement the login verification function for email sending. 1. Download and install PHPMa

Use uniapp to implement login verification function Use uniapp to implement login verification function Nov 21, 2023 pm 04:24 PM

Using uniapp to implement login verification function In modern network applications, login verification function is an indispensable part. Through the login verification function, the security of user identity can be ensured, and personalized data management of users can also be carried out. In uniapp, we can use some common techniques and code examples to implement login verification functionality. Below, we will use a simple example to introduce how to use uniapp to implement the login verification function. Example Requirement: Let's assume we have an app with login functionality.

How to use PHP functions to implement SMS verification code and login verification for user registration and login? How to use PHP functions to implement SMS verification code and login verification for user registration and login? Jul 26, 2023 pm 09:43 PM

How to use PHP functions to implement SMS verification code and login verification for user registration and login? With the development of mobile Internet and the popularity of smartphones, SMS verification codes have become a common method of user registration and login verification. This article will introduce how to use PHP functions to implement the SMS verification code function for user registration and login, and provide corresponding code examples. 1. Registration function When users register, they need to enter their mobile phone number and click the Send Verification Code button. The background sends messages to the mobile phone number by calling the interface of the third-party SMS platform.

How to perform user registration and login verification for PHP flash sale system How to perform user registration and login verification for PHP flash sale system Sep 21, 2023 pm 02:58 PM

Title: Detailed explanation of user registration and login verification of the PHP flash sale system. The PHP flash sale system is a common high-concurrency application. In order to ensure the stability and security of the system, user registration and login verification are indispensable links. This article will introduce in detail how to implement user registration and login verification of the PHP flash sale system, and provide specific code examples. 1. User registration User registration refers to the creation of accounts by users in the flash sale system. When implementing the user registration function, you need to pay attention to the following points: 1.1 Legality detection of user names and passwords

See all articles