Home
php教程
PHP源碼
The PHP web page generates a QR code, and the Android client scans the code to log in.



The PHP web page generates a QR code, and the Android client scans the code to log in.
Nov 08, 2016 am 11:41 AM使用了Github上具有掃碼功能的ZXing開源庫(kù),使用了通過隨機(jī)數(shù)生成二維碼圖片網(wǎng)絡(luò)API,整個(gè)過程經(jīng)過三步:
1.PHP網(wǎng)頁(yè)生成二維碼,相應(yīng)隨機(jī)數(shù)存儲(chǔ)到數(shù)據(jù)庫(kù)中;
2.Android客戶端掃碼,攜帶username保存至隨機(jī)數(shù)對(duì)應(yīng)的位置;
3.每隔一段時(shí)間,PHP通過Ajax輪詢數(shù)據(jù)庫(kù),判斷是否為空,不為空則跳轉(zhuǎn)網(wǎng)頁(yè)。
<html> <head> <title>qrlogin</title> <meta charset="UTF-8"/> </head> <body> <?php /** * @author Cenquanyu * @version 2016年5月12日 * */ require 'mysql_connect.php'; $randnumber = ""; for($i=0;$i<8;$i++){ $randnumber.=rand(0,9); } //將生成的隨機(jī)數(shù)保存至數(shù)據(jù)庫(kù) mysql_query("insert into login_data (randnumber) values ('$randnumber')") ?> <img src="/static/imghw/default1.png" data-src="http://qr.liantu.com/api.php?text=<?php echo $randnumber;? alt="The PHP web page generates a QR code, and the Android client scans the code to log in." >" class="lazy" width="300px"/> <input hidden="hidden" type="text" name="randnumber" id="randnumber"value="<?php echo $randnumber;?>"/> </body> <script> xmlHttpRequest.onreadystatechange = function(){ if(xmlHttpRequest.status == 200 && xmlHttpRequest.readyState ==4){ result = xmlHttp.responseText; if(result==true){//username不為空則跳轉(zhuǎn)頁(yè)面 window.location.href='welcome.php'; } } } } function polling(){ //執(zhí)行輪詢操作 var xmlHttpRequest; if(window.XMLHttpRequest){ xmlHttpRequest = new XMLHttpRequest(); } else{ xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP"); } randnumber = document.getElementById('randnumber').value; xmlHttpRequest.open("GET","polling.php?randnumber="+ randnumber,true); xmlHttpRequest.send(); } setInterval("polling()",1000); </script> </html>
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

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
Grass Wonder Build Guide | Uma Musume Pretty Derby
1 months ago
By Jack chen
Roblox: 99 Nights In The Forest - All Badges And How To Unlock Them
4 weeks ago
By DDD
Uma Musume Pretty Derby Banner Schedule (July 2025)
1 months ago
By Jack chen
RimWorld Odyssey Temperature Guide for Ships and Gravtech
3 weeks ago
By Jack chen
Windows Security is blank or not showing options
1 months ago
By 下次還敢

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)