原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://beastwu.blog.51cto.com/5091229/865707

本案是为客户的合作单位开发的无线网络的网页认证系统。
本系统实现基于Web的Windows Active Directory用户验证(域用户验证)与数据库用户验证,调用Wiwiz Auth API实现Web认证。

无线网络为客户现有环境,每层一个无线路由器接到交换机,以前用WPA,现改为Web网页认证方式。
网络结构经小幅改动,Web认证网关采用Wiwiz虚拟机。
认证页面程序使用PHP + MySQL,调用Wiwiz Auth API接口。

该公司有数百员工,网络使用方面规定较严格。多数员工只能上内网,少部分员工有使用外网的权限(客户OA系统中登记备案)。
MySQL数据库为客户的OA系统数据库。

有外网使用权限的员工可以使用公司的Windows域账户或者OA系统的账户登录并认证。
重要客户来访时接待人员还可以通过程序后台申请授权码。

认证页效果请参考下图(已隐去客户LOGO与名称):

以下附源码:

index.php

  1. <?php
  2. //****************************************************
  3. // Gets incoming parameters
  4. //****************************************************
  5. $pTokencode = $_REQUEST["tokencode"];   // incoming parameter "tokencode"
  6. $pSrvurl = $_REQUEST["srvurl"];     // incoming parameter "srvurl"
  7. session_start();
  8. if($pTokencode != null)
  9. $_SESSION['tokencode'] = $pTokencode;
  10. if($pSrvurl != null)
  11. $_SESSION['srvurl'] = $pSrvurl;
  12. ?>
  13. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  14. <html>
  15. <head>
  16. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  17. <meta http-equiv="Content-Language" content="zh">
  18. <meta http-equiv="Pragma" content="no-cache">
  19. <meta http-equiv="Cache-Control" content="no-cache">
  20. <title>Wifi Portal</title>
  21. <script>
  22. function onLogin1() {
  23. if(document.getElementById("AuthType0").checked == false && document.getElementById("AuthType1").checked == false) {
  24. alert("请选择“使用OA系统账户登录”或“使用域账号登录”。");
  25. return false;
  26. }
  27. if(document.getElementById("agree1").checked == false) {
  28. alert("认证前您需要阅读并认同公司《计算机及网络使用管理规定》。");
  29. return false;
  30. }
  31. return true;
  32. }
  33. function onLogin2() {
  34. if(document.getElementById("agree2").checked == false) {
  35. alert("认证前您需要阅读并认同《访客使用网络协议》。");
  36. return false;
  37. }
  38. return true;
  39. }
  40. </script>
  41. </head>
  42. <body>
  43. <form action="auth.php" method="post">
  44. <center>
  45. <br>
  46. <font style="font-size:22px" color="red">
  47. <b>XXX公司WiFi认证系统</font>
  48. <br><br>
  49. <font style="font-size:14px">
  50. 本公司、子公司及合作单位员工请使用OA系统账户或域账户进行认证
  51. <br>
  52. (仅限开通使用Internet权限的员工)
  53. <br><br>
  54. 访客请使用授权码进行认证
  55. </font></b>
  56. <br>
  57. <br>
  58. <table width="760">
  59. <tr>
  60. <td width="60%">
  61. <table width="90%" height="340" border="0" cellspacing="1" cellpadding="5" bgcolor="#cccccc" style="font-size: 12px">
  62. <tr bgcolor="#eef1ff">
  63. <td align=center>
  64. <b><font style="font-size:14px">员工通道</b></font>
  65. <table style="font-size:12px">
  66. <tr>
  67. <td colspan=2>
  68. <br>
  69. <input type="radio" name="AuthType" id="AuthType0" value="0" /> <label for="AuthType0">使用OA系统账户登录</label>
  70. </td>
  71. </tr>
  72. <tr>
  73. <td>
  74. 工号:
  75. </td>
  76. <td>
  77. <input type="text" name="StaffId" />
  78. </td>
  79. </tr>
  80. <tr>
  81. <td>
  82. 密码:
  83. </td>
  84. <td>
  85. <input type="password" name="Pswd" />
  86. </td>
  87. </tr>
  88. <tr>
  89. <td colspan=2>
  90. <input type="radio" name="AuthType" id="AuthType1" value="1" /> <label for="AuthType1">使用域账号登录</label>
  91. </td>
  92. </tr>
  93. <tr>
  94. <td>
  95. 所在域:
  96. </td>
  97. <td>
  98. <select name="Domain">
  99. <option value="MD">MD</option>
  100. <option value="Marketing">Marketing</option>
  101. </select>
  102. </td>
  103. </tr>
  104. <tr>
  105. <td>
  106. 域账户名:
  107. </td>
  108. <td>
  109. <input type="text" name="DomainUser" />
  110. </td>
  111. </tr>
  112. <tr>
  113. <td>
  114. 密码:
  115. </td>
  116. <td>
  117. <input type="password" name="DomainPswd" />
  118. </td>
  119. </tr>
  120. </table>
  121. <br>
  122. <input type="checkbox" name="agree1" id="agree1"><label for="agree1">我已阅读公司《<a href="http://172.23.1.16/hr/docs/k/12_doc.htm">计算机及网络使用管理规定</a>》</label>
  123. <br><br>
  124. <input type="submit" value="  登录 / 认证  " name="login1" οnclick="return onLogin1();" />
  125. </td>
  126. </tr>
  127. </table>
  128. </td>
  129. <td width="40%">
  130. <table width="90%" height="340" border="0" cellspacing="1" cellpadding="8" bgcolor="#cccccc" style="font-size: 12px">
  131. <tr bgcolor="#eef1ff">
  132. <td>
  133. <center>
  134. <b><font style="font-size:14px">访客通道</b></font>
  135. <br><br>
  136. <table style="font-size:12px">
  137. <tr>
  138. <td colspan=2>
  139. <center> 访客请使用授权码进行认证 <br><br>
  140. </td>
  141. </tr>
  142. <tr>
  143. <td>
  144. 授权码:
  145. </td>
  146. <td>
  147. <input type="text" style="width:100px" name="AuthCode" />
  148. </td>
  149. </tr>
  150. </td>
  151. </tr>
  152. </table>
  153. <br>
  154. <input type="checkbox" name="agree2" id="agree2"><label for="agree2">我已阅读并认同《<a href="http://172.23.1.16/hr/docs/k/11_doc.htm">访客使用网络协议</a>》</label>
  155. <br><br>
  156. <input type="submit" value="  认证  " name="login2" οnclick="return onLogin2();" />
  157. <br>
  158. <br>
  159. </center>
  160. *注: 如您正在访问本公司并需要使用本公司WiFi网络,请联系您的接待人员或客户经理以索取授权码
  161. </td>
  162. </tr>
  163. </table>
  164. </td></tr></table>
  165. <br>
  166. <font size=-1>帮助热线:内线5220
  167. </center>
  168. </form>
  169. </body>
  170. </html>

auth.php

  1. <?php
  2. session_start();
  3. $AD_HOST = "XXXXXX:389";    // Active Directory服务器
  4. $userkey = "XXXXXX";    // Wiwiz User Key
  5. $loginSuccess = false;
  6. if(isset($_POST['login1'])) {
  7. if($_POST['AuthType'] == '0' ) {            //员工通道 - 使用OA系统账户登录并认证
  8. $StaffId = $_POST['StaffId'];
  9. $Pswd = $_POST['Pswd'];
  10. if($StaffId == '')
  11. die("请输入工号!" );
  12. if($Pswd == '')
  13. die("请输入密码!" );
  14. $db = mysql_connect("localhost", "root") or die("OA系统连接异常!");
  15. //$db = mysql_connect(":/tmp/mysql.sock", "root") or die("OA系统连接异常!");
  16. mysql_select_db("oadb",$db);
  17. $result = mysql_query("SELECT count(staffid) as cnt FROM usermaster where staffid='". mysql_real_escape_string($StaffId) ."' and pswd='". mysql_real_escape_string($Pswd) ."'", $db);
  18. $cnt = mysql_result($result, 0, "cnt");
  19. mysql_close($db);
  20. if($cnt <> '0')
  21. $loginSuccess = true;
  22. } else if($_POST['AuthType'] == '1' ) { //员工通道 - 使用域账户登录并认证
  23. $DomainUser = $_POST['DomainUser'];
  24. $DomainPswd = $_POST['DomainPswd'];
  25. $Domain = $_POST['Domain'];
  26. if($DomainUser == '')
  27. die("请输入域账户名!" );
  28. if($DomainPswd == '')
  29. die("请输入域账户密码!" );
  30. if($Domain == '')
  31. die("请选择所在域!" );
  32. $conn = ldap_connect($AD_HOST) or die("连接失败!" );
  33. if($conn){
  34. //
  35. ldap_set_option ( $conn, LDAP_OPT_PROTOCOL_VERSION, 3 );
  36. ldap_set_option ( $conn, LDAP_OPT_REFERRALS, 0 ); // Binding to ldap server
  37. $bd = ldap_bind($conn, $DomainUser.'@'.$Domain, $DomainPswd); //  or die ("域账户或密码错误。");
  38. if($bd)
  39. $loginSuccess = true;
  40. } else{
  41. echo "连接失败!";
  42. }
  43. }
  44. }
  45. if(isset($_POST['login2'])) {               //访客通道(使用授权码认证)
  46. $AuthCode = $_POST['AuthCode'];
  47. if($AuthCode == '')
  48. die("请输授权码!" );
  49. $db = mysql_connect("localhost", "root") or die("OA系统连接异常!");
  50. mysql_select_db("oadb",$db);
  51. $result = mysql_query("SELECT count(id) as cnt FROM authcode where code='". mysql_real_escape_string($AuthCode). "'", $db);
  52. $cnt = mysql_result($result, 0, "cnt");
  53. mysql_close($db);
  54. if($cnt <> '0')
  55. $loginSuccess = true;
  56. }
  57. //
  58. // Do something you need.
  59. // e.g. verify the user
  60. //      ......
  61. //
  62. if($loginSuccess == false) {
  63. echo "认证失败!";   // if user login failed, show an error message
  64. } else {
  65. //****************************************************
  66. // Step 2. Do the pre-auth by calling Wiwiz Auth API
  67. // IMPORTANT: Do this on your server side(ASP, C#, JSP/Servlet, PHP...),
  68. //            but DO NOT do this on your client side (HTML/Javascript)
  69. //****************************************************
  70. // parameter "action" : REQUIRED!
  71. // set it to "1" to authenticate the user
  72. // set it to "0" to block the user
  73. $action = "1";
  74. // parameter "tokencode": REQUIRED!
  75. // set identical to the incoming parameter
  76. $tokencode = $_SESSION['tokencode'];
  77. // parameter "srvurl": REQUIRED!
  78. // set identical to the incoming parameter
  79. $srvurl = $_SESSION['srvurl'];
  80. // parameter "endtime" : OPTIONAL
  81. // Format: yyyy-mm-dd hh:MM:ss  e.g. 2012-05-31 21:39:00
  82. // set this parameter to set the time to close the user's Internet connection
  83. // Note: the value must be url-encoded.
  84. //  $endtime = urlencode('2012-05-31 21:39:00');
  85. $endtime = '';
  86. // parameter "postauth" : OPTIONAL
  87. // E.g. http://www.YourDomain.com
  88. // set this parameter to redirect to a specified URL after authenticated.
  89. // Note: the value should be url-encoded.
  90. //$postauth = urlencode("http://www.wiwiz.com");
  91. $postauth = '';
  92. $parameters = "?wiwiz_auth_api=1&ver=1.0". // parameter "wiwiz_auth_api" and "ver". Fixed value
  93. "&tokencode=". $tokencode . // parameter "tokencode". See above
  94. "&userkey=". $userkey .     // parameter "userkey". Set your own User Key
  95. "&action=". $action .       // parameter "action". See above
  96. "&endtime=". $endtime .     // parameter "endtime". See above
  97. "&postauth=". $postauth;    // parameter "postauth". See above
  98. $verifycode = file_get_contents($srvurl . $parameters);
  99. if (strpos ($verifycode, "ERR") === 0) {
  100. // if there is an error, show error code
  101. echo "Error: ". $verifycode;
  102. } else {
  103. // OK, now. do Step 3.
  104. //****************************************************
  105. // Step 3. Complete the Authentication by calling Wiwiz Auth API
  106. //****************************************************
  107. $redirectUrl = $srvurl.     // use the value of incoming parameter "srvurl" as the redirection address
  108. "?wiwiz_auth_api_login=1".  // parameter "wiwiz_auth_api_login"
  109. "&tokencode=". $tokencode . // parameter "tokencode", set identical to the incoming parameter
  110. "&verifycode=". $verifycode;    // parameter "verifycode", set identical to the incoming parameter
  111. ob_start();
  112. header("Location: ". $redirectUrl); // finally, do the redirection
  113. ob_flush();
  114. //          echo "<script>location.href=\"". $redirectUrl ."\"</script>";
  115. }
  116. }
  117. ?>

本文出自 “野兽技术博客” 博客,请务必保留此出处http://beastwu.blog.51cto.com/5091229/865707

转载于:https://blog.51cto.com/2955941/903976

转用PHP开发企业Wifi网络Web认证系统(附源码)相关推荐

  1. 用PHP开发企业Wifi网络Web认证系统(附源码)

    文字转载自https://blog.51cto.com/beastwu/865707 本案是为客户的合作单位开发的无线网络的网页认证系统. 本系统实现基于Web的Windows Active Dire ...

  2. java毕业设计创新学分认证系统mybatis+源码+调试部署+系统+数据库+lw

    java毕业设计创新学分认证系统mybatis+源码+调试部署+系统+数据库+lw java毕业设计创新学分认证系统mybatis+源码+调试部署+系统+数据库+lw 本源码技术栈: 项目架构:B/S ...

  3. 新版WIFI小程序分销系统微信源码序WiFi大师版流量主搭建独立源码WiFi分销源码

    网传版本,未测试,新版WIFI大师v4.47小程序源码,WIFI分销系统带流量主和独立运行版. 更新内容: 1.后台更多板块列表新增分页 2.平台管理端图标优化 3.平台管理端新增平台统计 4.优化后 ...

  4. 计算机毕业设计Java中文网络小说平台系统(源码+系统+mysql数据库+lw文档)

    计算机毕业设计Java中文网络小说平台系统(源码+系统+mysql数据库+lw文档) 计算机毕业设计Java中文网络小说平台系统(源码+系统+mysql数据库+lw文档) 本源码技术栈: 项目架构:B ...

  5. java毕业生设计中文网络小说平台系统计算机源码+系统+mysql+调试部署+lw

    java毕业生设计中文网络小说平台系统计算机源码+系统+mysql+调试部署+lw java毕业生设计中文网络小说平台系统计算机源码+系统+mysql+调试部署+lw 本源码技术栈: 项目架构:B/S ...

  6. JAVA计算机毕业设计中文网络小说平台系统Mybatis+源码+数据库+lw文档+系统+调试部署

    JAVA计算机毕业设计中文网络小说平台系统Mybatis+源码+数据库+lw文档+系统+调试部署 JAVA计算机毕业设计中文网络小说平台系统Mybatis+源码+数据库+lw文档+系统+调试部署 本源 ...

  7. java毕业生设计校园统一网络授课平台系统计算机源码+系统+mysql+调试部署+lw

    java毕业生设计校园统一网络授课平台系统计算机源码+系统+mysql+调试部署+lw java毕业生设计校园统一网络授课平台系统计算机源码+系统+mysql+调试部署+lw 本源码技术栈: 项目架构 ...

  8. 在线计算机考试系统源代码,在线考试系统 附源码和文档

    [实例简介] 在线考试系统 附源码和文档. 做毕业设计,课程设计或者正在学习相关技术知识的朋友可以下载资源学习.想继续学习相关知识的可以关注我. [实例截图] [核心代码] 在线考试系统4 └── S ...

  9. Shark(鲨鱼记账系统)--附源码

    Shark(鲨鱼记账系统)–附源码 程序员就要多撸代码,以便在脑海中形成深刻记忆,昨晚试着撸了一个小小的记账系统,内容很简单,主要负责简单的记账,不过没用到持久层,后续会做持久层的版本,先看个简单的把 ...

最新文章

  1. mysql5.5安装
  2. python输出乘法口诀-【每日一练】python输出 9*9 乘法口诀表
  3. 获取android屏幕大小
  4. rabittmq java spring_消息队列 RabbitMQ 与 Spring 整合使用的实例代码
  5. 联想确认再次裁员 称调整主要分布在海外
  6. linux指向域同步时间,linux在局域网下设置时间同步
  7. ECMAScript6入门简介篇
  8. 同级子目录下重新设置属性失效
  9. “互联网+”促传统企业三大转型
  10. LVS/keepalived配置
  11. 监听js变量的变化_JS监听事件型爬虫
  12. android 自定义指南针,如何在android中制作自定义指南针视图
  13. Java 算法 开灯游戏
  14. Shiro - Shiro简介;Shiro与Spring Security区别;Spring Boot集成Shiro
  15. 马尔可夫过程 与 隐马尔科夫模型
  16. plecs / plexim 学习随笔
  17. 配置maven使用阿里云仓库
  18. 某个程序员的工作记录
  19. Unity3D游戏开发引擎的产品特点
  20. [优雅代码]-调用java集合Map.computeIfAbsent()方法

热门文章

  1. Python处理MLDonkey 下载中文文件乱码问题 (2)
  2. pycharm中导入allure提示模块不存在解决方法
  3. Xamarin图表开发基础教程(3)OxyPlot框架
  4. UGUI的优点新UI系统
  5. php上传头像的代码,php头像上传预览实例代码
  6. php运行出来一堆乱码,一堆乱码中找到的~_php
  7. 怎么通过python挣外快_利用Python爬虫轻松挣外快的几个方法(值得收藏)
  8. 卡尔曼滤波对gps轨迹数据清洗_卡尔曼滤波:从入门到精通
  9. python编写圣诞树代码_python 实现圣诞树
  10. Nature子刊:基于水凝胶的灵活脑机接口