首頁 php教程 PHP源码 PHP網頁產生二維碼,Android客戶端掃碼登入

PHP網頁產生二維碼,Android客戶端掃碼登入

Nov 08, 2016 am 11:41 AM

使用了Github上具有扫码功能的ZXing开源库,使用了通过随机数生成二维码图片网络API,整个过程经过三步:
1.PHP网页生成二维码,相应随机数存储到数据库中;
2.Android客户端扫码,携带username保存至随机数对应的位置;

3.每隔一段时间,PHP通过Ajax轮询数据库,判断是否为空,不为空则跳转网页。

<html>
  <head>
    <title>qrlogin</title>
    <meta charset="UTF-8"/>
  </head>
  <body>
    <?php
    /**
     * @author Cenquanyu
     * @version 2016年5月12日
     *
     */
       require &#39;mysql_connect.php&#39;;
       $randnumber = "";
       for($i=0;$i<8;$i++){
       $randnumber.=rand(0,9);
       }
       //将生成的随机数保存至数据库
       mysql_query("insert into login_data (randnumber) values (&#39;$randnumber&#39;)")
        
    ?>
     
   <img  src="/static/imghw/default1.png"  data-src="http://qr.liantu.com/api.php?text=<?php echo $randnumber;? alt="PHP網頁產生二維碼,Android客戶端掃碼登入" >"  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不为空则跳转页面
         window.location.href=&#39;welcome.php&#39;;
    }
}
}
  }
  function polling(){
 
      //执行轮询操作
      var xmlHttpRequest;
      if(window.XMLHttpRequest){
          xmlHttpRequest = new XMLHttpRequest();
          }
      else{
          xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
      }
       randnumber = document.getElementById(&#39;randnumber&#39;).value;
       xmlHttpRequest.open("GET","polling.php?randnumber="+ randnumber,true);
       xmlHttpRequest.send();
  }
       setInterval("polling()",1000);
</script>
 
</html>
登入後複製


本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)