Home > php教程 > php手册 > 极验验证类

极验验证类

WBOY
Release: 2016-06-07 11:40:35
Original
1310 people have browsed it

极验验证码类
效果图:极验验证类
类Geetestlib.class.php<?php <br /> /**<br>  * 极验验证类<br>  * @category   ORG<br>  * @package  ORG<br>  * @subpackage  Net<br>  * @author    liujing <liujin0506><br>  */<br> class Geetestlib {<br> <br> public function geetest_validate($challenge, $validate, $seccode, $key) {    <br>     $apiserver = 'api.geetest.com';<br>     if (strlen($validate) > 0 && $this->check_result_by_private($challenge, $validate, $key)) {        <br>         $query = 'seccode='.$seccode;<br>         $servervalidate = $this->http_post($apiserver, '/validate.php', $query);            <br>         if (strlen($servervalidate) > 0 && $servervalidate == md5($seccode)) {<br>             return TRUE;<br>         }<br>     }<br>     <br>     return FALSE;        <br> }<br> <br> private function check_result_by_private($origin, $validate, $key) {<br>     return $validate == md5($key.'geetest'.$origin) ? TRUE : FALSE;<br> }<br> <br> private function http_post($host, $path, $data, $port = 80) {<br>     // $data = $this->fix_encoding($data);<br>     <br>     $http_request  = "POST $path HTTP/1.0\r\n";<br>     $http_request .= "Host: $host\r\n";<br>     $http_request .= "Content-Type: application/x-www-form-urlencoded\r\n";<br>     $http_request .= "Content-Length: " . strlen($data) . "\r\n";<br>     $http_request .= "\r\n";<br>     $http_request .= $data;<br> <br>     $response = '';<br>     if (($fs = @fsockopen($host, $port, $errno, $errstr, 10)) == false) {<br>         die ('Could not open socket! ' . $errstr);<br>     }<br>     <br>     fwrite($fs, $http_request);<br> <br>     while (!feof($fs))<br>         $response .= fgets($fs, 1160);<br>     fclose($fs);<br>     <br>     $response = explode("\r\n\r\n", $response, 2);<br>     return $response[1];<br> }<br> <br> private function fix_encoding($str) {     <br>     $curr_encoding = mb_detect_encoding($str) ; <br>     <br>     if($curr_encoding == "UTF-8" && mb_check_encoding($str,"UTF-8")) {<br>         return $str; <br>     } else {<br>         return utf8_encode($str); <br>     }<br> }<br> }<br> <br> ?></liujin0506>控制器处理代码:import('ORG.Net.Geetestlib');<br>         $verify = new Geetestlib();<br>         $key = C('verifykey');<br>         $validate_response = $verify->geetest_validate(@$_POST['geetest_challenge'], @$_POST['geetest_validate'], @$_POST['geetest_seccode'],$key);<br>         if(empty($validate_response)) {<br>             $this->error('验证码错误!');<br>         }前端处理代码:<script></script>(这里注意id的绑定)

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template