Home php教程 php手册 一个完整php验证码实例程序

一个完整php验证码实例程序

May 25, 2016 pm 04:40 PM
php verification code

<!doctype html> 
<html xml:lang="en-us" xmlns="http://www.w3.org/1999/xhtml"> 
<title>login</title> 
<link rel="stylesheet" type="text/css" href="/tryit.css" /> 
<script type="text/javascript"> 
function getpinimg() 
{ 
    document.getelementbyid("pinimg").src="log_demo.php?a=pin&r=" + math.random(); 
} 
</script> 
</head> 
 
<body> 
<form action="log_demo.php" method="get"> 
 <input type="hidden" name="a" value="log" /> 
 user:<input type="text" name="user" size="20" value="test" /><br /><br /> 
 password:<input type="password" name="pass" size="12" value="123456" /><br /><br /> 
 pincode:<input type="text" name="pin" size="8" value="" />  
 <input type="button" value="getpin" onclick="getpinimg();"> 
   <img  src="/static/imghw/default1.png"  data-src="log_demo.php?a=pin"  class="lazy"  id="pinimg"  onclick="getpinimg();" / alt="一个完整php验证码实例程序 " >  
 <input type="submit" value="submit"><br /> 
</form> 
</body> 
</html>
Copy after login

log_demo.php代码如下:

<?php
require_once ("log_aux.php");
if ($_get[&#39;a&#39;] == "pin") {
    getpinimg();
    exit;
}
if ($_get[&#39;a&#39;] == "log") {
    $ret = checkpincookie($_get[&#39;pin&#39;], 300);
    if ($ret < 0) { //开源代码phprm.com
        echo "pin error:$ret ";
        exit;
    }
    // check user name and password.
    echo "ok..$ret ";
    if ("123xx" == 123) {
        echo "dddd ";
    }
    echo $_get[&#39;u&#39;];
}
?>
Copy after login

log_aux.php代码如下:

<?php
$magic_a = "www.phprm.com34589";
$magic_b = "234566***+";
function getpincookie($pin_code) {
    global $magic_a;
    global $magic_b;
    $now = time();
    $client_ip = $_server[&#39;remote_addr&#39;];
    $pin = md5($now . $client_ip . $magic_a . $pin_code . $maigc_b) . $now;
    return $pin;
}
function checkpincookie($pin_code_in, $timeout = 300) // 5 miniuteswww.phprm.com
{
    global $magic_a;
    global $magic_b;
    $pin = substr($_cookie[&#39;pin&#39;], 0, 32);
    $time = substr($_cookie[&#39;pin&#39;], 32);
    $now = time();
    if ($now - $time > $timeout) {
        return -100; // time_out
        
    }
    $pin_code_in = strtolower($pin_code_in);
    $client_ip = $_server[&#39;remote_addr&#39;];
    $pin_2 = md5($time . $client_ip . $magic_a . $pin_code_in . $maigc_b);
    if ($pin === $pin_2) {
        return 0;
    } else {
        return -200; // pincode is error.
        
    }
}
function getpinimg() {
    // $rnd = rand(0, 10);
    $rnd = 0;
    $path = "./www.phprm.com/" . substr("00000$rnd", -4);
    for ($i = 0; $i < 4; ++$i) {
        if (__getpinimg($path)) {
            break;
        }
    }
    exit;
}
function __getpinimg($path) {
    require ("$path/pinmap.php");
    $pinv = $pin[rand(0, $pin_max) ];
    list($file, $pin_code) = explode(&#39;#&#39;, $pinv);
    $filepath = "$path/$file$pin_ext";
    //  output pincode image.
    $fh = fopen($filepath, "rb");
    if (!$fh) {
        return false;
    }
    $data = fread($fh, 10240); // php just read max size: 8k.
    fclose($fh);
    if (strlen($data) < 200) {
        return false;
    }
    // set cookie;
    header("content-type: image/jpeg");
    $pin_code = strtolower($pin_code);
    $pin = getpincookie($pin_code);
    setcookie("pin", $pin);
    echo $data;
    return true;
}
Copy after login


永久链接:

转载随意!带上文章地址吧。

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)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 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)