A complete PHP Verification code instance program [with demo]

Source: Internet
Author: User
Tags md5 php code php tutorial rand set cookie
The code is as follows Copy Code

<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.111cn.net/tr/xhtml1/dtd/ Xhtml1-transitional.dtd ">
<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>

<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 ();" >

<input type= "Submit" value= "Submit" ><br/>
</form>
</body>

log_demo.php Code

The code is as follows Copy 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: $ret";
Exit
}
Check user name and password.
echo "OK ... $ret ";
if ("123xx" = 123) {
echo "dddd";
}
echo $_get[' u '];
}

log_aux.php Code

The code is as follows Copy Code

<?php
$magic _a = "www.111cn.net34589";
$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.111cn.net
{
 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 _cod e_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.111cn.net/". 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 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;
}

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.