A complete PHP Verification code instance program [with demo]

Source: Internet
Author: User
Keywords Web Programming PHP Tutorials
Tags client code css tutorial data echo exit function html

HTML Invoke PHP Tutorial Verification Code Program

<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.jzread.com/tr/xhtml1/dtd/xhtml1-transitional.dtd" >
<html lang= "en-us" xml:lang= "en-US" xmlns= "http://www.w3.org/1999/xhtml" >
<title>login</title>
<link rel= "stylesheet" type= "text/css Tutorial" href= "/tryit.css Tutorial"/>
<script type= "text/web Effects" >
function getpinimg ()
{
document.getElementById ("Pinimg"). src= "log_demo.php tutorial? 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= "value=" "Test"/><br/><br/>
Password:<input type= "password" name= "pass" size= "" value= "123456"/><br/><br/>
Pincode:<input type= "text" Name= "pin" size= "8" value= ""/>
<input type= "button" value= "Getpin" onclick= "getpinimg ();" >
<img id= "pinimg" src= "Log_demo.php?a=pin" onclick= "getpinimg" (); "/>
<input type= "Submit" value= "Submit" ><br/>
</form>
</body>
</html>
log_demo.php Code

<?php
Require_once ("log_aux.php");

if ($_get[' a '] = = "pin") {
Getpinimg ();
Exit;
}

if ($_get[' a '] = = "Log") {
$ret = Checkpincookie ($_get[' pin '), 300);
if ($ret < 0) {
echo "Pin error: $RETN";
Exit;
}
Check user name and password.
echo OK ... $retn ";
if ("123xx" = 123) {
echo "DDDDN";
}
echo $_get[' u '];
}
log_aux.php Code

<?php
$magic _a = "www.jzread.com34589";
$magic _b = "234566***+";

function Getpincookie ($pin _code)
{
Global $magic _a;
Global $magic _b;
$now = time ();
$client _ip = $_server[' remote_addr '];
$pin = MD5 ($now. $client _ip. $magic _a. $pin _code. $MAIGC _b). $now;
return $pin;
}

function Checkpincookie ($pin _code_in, $timeout =300)//5 miniuteswww.jzread.com
{
Global $magic _a;
Global $magic _b;
$pin = substr ($_cookie[' pin '), 0, 32);
$time = substr ($_cookie[' pin '), 32);
$now = time ();
if ($now-$time > $timeout) {
return-100; Time_out
}
$pin _code_in = strtolower ($pin _code_in);
$client _ip = $_server[' remote_addr '];
$pin _2 = MD5 ($time. $client _ip. $magic _a. $pin _code_in);
if ($pin = = = $pin _2) {
return 0;
else {
return-200; Pincode is error.
}
}

function getpinimg ()
{
$rnd = rand (0, 10);
$rnd = 0;
$path = "./www.jzread.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 (' # ', $PINV);
$filepath = "$path/$file $pin_ext";

Output pincode image.
$fh = fopen ($filepath, "RB");
if (! $fh) {
return false;
}
$data = Fread ($fh, 10240); PHP ethically 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;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.