亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

php驗證碼類

系統 2115 0

1. php驗證碼類 點擊可刷新

?

1、驗證碼類文件 CreateImg.class.php

      <?php

class ValidationCode
{
private $width,$height,$codenum;
public $checkcode;     //產生的驗證碼
private $checkimage;    //驗證碼圖片
private $disturbColor = ''; //干擾像素

function __construct($width='80',$height='20',$codenum='4')
{
   $this->width=$width;
   $this->height=$height;
   $this->codenum=$codenum;
}
function outImg()
{
   //輸出頭
   $this->outFileHeader();
   //產生驗證碼
   $this->createCode();

   //產生圖片
   $this->createImage();
   //設置干擾像素
   $this->setDisturbColor();
   //往圖片上寫驗證碼
   $this->writeCheckCodeToImage();
   imagepng($this->checkimage);
   imagedestroy($this->checkimage);
}

private function outFileHeader()
{
   header ("Content-type: image/png");
}

private function createCode()
{
   $this->checkcode = strtoupper(substr(md5(rand()),0,$this->codenum));
}

private function createImage()
{
   $this->checkimage = @imagecreate($this->width,$this->height);
   $back = imagecolorallocate($this->checkimage,255,255,255);
   $border = imagecolorallocate($this->checkimage,0,0,0);  
   imagefilledrectangle($this->checkimage,0,0,$this->width - 1,$this->height - 1,$back); // 白色底
   imagerectangle($this->checkimage,0,0,$this->width - 1,$this->height - 1,$border);   // 黑色邊框
}

private function setDisturbColor()
{
   for ($i=0;$i<=200;$i++)
   {
    $this->disturbColor = imagecolorallocate($this->checkimage, rand(0,255), rand(0,255), rand(0,255));
    imagesetpixel($this->checkimage,rand(2,128),rand(2,38),$this->disturbColor);
   }
}

private function writeCheckCodeToImage()
{
   for ($i=0;$i<=$this->codenum;$i++)
   {
    $bg_color = imagecolorallocate ($this->checkimage, rand(0,255), rand(0,128), rand(0,255));
    $x = floor($this->width/$this->codenum)*$i;
    $y = rand(0,$this->height-15);
    imagechar ($this->checkimage, rand(5,8), $x, $y, $this->checkcode[$i], $bg_color);
   }
}
function __destruct()
{
   unset($this->width,$this->height,$this->codenum);
}
}
?>
    

?

2、包含文件 imgcode.php

      <?php
session_start();
require_once('CreateImg.class.php');
$image = new ValidationCode('80','20','4');    //圖片長度、寬度、字符個數
$image->outImg();
$_SESSION['validationcode'] = $image->checkcode; //存貯驗證碼到 $_SESSION 中
?>
    

?

3、前臺文件 demo.php

      ?php
session_start();
$test = $_POST['test'];
$test = strtoupper(trim($test));
$submit = $_POST['submit'];
if(isset($submit)){
if($test==$_SESSION['validationcode']){
   echo 'true';
} else {
   echo 'false';
}
}
?>

<html>
<head>
<title>Image</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<script language="javascript">
function newgdcode(obj,url) {
obj.src = url+ '?nowtime=' + new Date().getTime();
//后面傳遞一個隨機參數,否則在IE7和火狐下,不刷新圖片
}
</script>
<body>
<img src="imgcode.php" alt="看不清楚,換一張" align="absmiddle" style="cursor: pointer;" onclick="javascript:newgdcode(this,this.src);" />
<form method="POST" name="form1" action="image.php">
<input type="text" name="test">
<br />
<input type="submit" name="submit" value="提交">
</form>
</body>
</head>
</html>
    

?

2. jQuery插件Real Person 點擊可刷新

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.realperson.js"></script>
<link href="jquery.realperson.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
	$(function(){
		$('#Gideon').realperson({length: 5});
	})
</script>
</head>

<body>

<input type="text" id="Gideon" name="defaultReal">
</body>
</html>
    

?

來源: http://keith-wood.name/realPerson.html

?

注:如果持續無法驗證成功的話,請嘗試下面的方法:

      <?php
function rpHash($value) {
	$hash = 5381;
	$value = strtoupper($value);
	for($i = 0; $i < strlen($value); $i++) {
		$hash = (($hash << 5) + $hash) + ord(substr($value, $i));
	}
	return $hash;
}
?>
    

?

替換為:

      <?
	function rpHash($value) 
	{
	    $hash = 5381;
	    $value = strtoupper($value);
	    for($i = 0; $i < strlen($value); $i++)  $hash = (leftShift32($hash, 5) + $hash) + ord(substr($value, $i));
	    return $hash; 
	}

	function leftShift32($number, $steps) 
	{
	    $binary = decbin($number);
	    $binary = str_pad($binary, 32, "0", STR_PAD_LEFT);
	    $binary = $binary.str_repeat("0", $steps);
	    $binary = substr($binary, strlen($binary) - 32);
	    return ($binary{0} == "0" ? bindec($binary) : -(pow(2, 31) - bindec(substr($binary, 1)))); 
	}
?>
    

?

3. php驗證碼 可計算(有限)

demo.php

      <?php
session_start();
if(!empty($_POST['Login'])){
	if(md5(strtoupper($_POST['Login'])) == $_SESSION['Login']){
		echo 'Correct';
	}else{
		echo 'Error';	
	}
}
?>

<form method="post">
    <input type="text" name="Login" value="" /><img src="img.php?Action=Login&imgW=80&imgH=30" align="absmiddle">
    <input type="submit" value="Login" />
</form>
    

?

img.php

      <?php
session_start();
  /**
* 隨機的數字,之和驗證碼
* 修改日期 2006-12-20
*/
function getCode ($length = 32, $mode = 0)
{
switch ($mode)
{
     case '1':
         $str = '123456789';
            break;
  case '2':
            $str = 'abcdefghijklmnopqrstuvwxyz';
            break;
  case '3':
            $str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
            break;
  case '4':
            $str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
            break;
  case '5':
            $str = 'ABCDEFGHIJKLMNPQRSTUVWXYZ123456789';
            break;
        case '6':
            $str = 'abcdefghijklmnopqrstuvwxyz1234567890';
            break;
        default:
            $str = 'ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789';
            break;
}

$result = '';
$l = strlen($str)-1;
for($i = 0;$i < $length;$i ++)
{
  $num = rand(0, $l);
  $result .= $str[$num];
}
return $result;
}
//建立驗證圖片
function createAuthNumImg($randStr,$imgW=100,$imgH=40,$fontName)
{
header ("content-type: image/png");
$image = imagecreate($imgW , $imgH);
$color_white = imagecolorallocate($image , 255 , 255 , 255);
$color_gray  = imagecolorallocate($image , 228 , 228 , 228);
$color_black = imagecolorallocate($image , 255 , 102 , 204);
for ($i = 0 ; $i < 1000 ; $i++)
{
  imagesetpixel($image , mt_rand(0 , $imgW) , mt_rand(0 , $imgH) , $color_gray);
}
imagerectangle($image , 0 , 0 , $imgW - 1 , $imgH - 1 , $color_gray);
for ($i=10;$i<$imgH;$i+=10)
  imageline($image, 0, $i, $imgW, $i, $color_gray);
imagettftext($image,16,5,3,25,$color_black,$fontName,$randStr);
for ($i=10;$i<$imgW;$i+=10)
  imageline($image, $i, 0, $i, $imgH, $color_gray);
imagepng($image);
imagedestroy($image);
}

$a=GetCode(1,1);
$b=GetCode(1,1);
$c=GetCode(1,1);
$Passport=$a."+".$b."+".$c;
$Total=$a+$b+$c;
$Total;
$_SESSION[$_GET['Action']]=md5(strtoupper($Total));
createAuthNumImg($Passport,$_GET['imgW'],$_GET['imgH'],"verdana.ttf");
?>
    

?

3. Recaptcha(需要申請key,不過是免費的,類似Google key)

官網: http://recaptcha.net/resources.html

?

php驗證碼類

?

Examples

The following is a "Hello World" with reCAPTCHA:

      <html>
  <body>
    <form action="" method="post">
<?php

require_once('recaptchalib.php');

// Get a key from http://recaptcha.net/api/getkey
$publickey = "6Lfc4wsAAAAAAM2-W6LHIYIA0NphCqZniVIXAKmp";
$privatekey = "6Lfc4wsAAAAAAEat7eqgrzOim3HG_lrzQ9_fvzwU";

# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;

# was there a reCAPTCHA response?
if ($_POST["recaptcha_response_field"]) {
        $resp = recaptcha_check_answer ($privatekey,
                                        $_SERVER["REMOTE_ADDR"],
                                        $_POST["recaptcha_challenge_field"],
                                        $_POST["recaptcha_response_field"]);

        if ($resp->is_valid) {
                echo "You got it!";
        } else {
                # set the error code so that we can display it
                $error = $resp->error;
        }
}
echo recaptcha_get_html($publickey, $error);
?>
    <br/>
    <input type="submit" value="submit" />
    </form>
  </body>
</html>
    

?

The following example shows how to use Mailhide:

?

      <html><body>
<?
require_once ("recaptchalib.php");
// get a key at http://mailhide.recaptcha.net/apikey
$mailhide_pubkey = '';
$mailhide_privkey = '';
?>
The Mailhide version of example@example.com is
<?
echo recaptcha_mailhide_html ($mailhide_pubkey,
                              $mailhide_privkey,
                              "example@example.com");
?>.
<br>
The url for the email is:
<?
echo recaptcha_mailhide_url ($mailhide_pubkey,
                             $mailhide_privkey,
                             "example@example.com");
?>
<br>
</body></html>

    

?

If you're looking for some more examples, take a look at the WordPress and MediaWiki plugins, which use this library.

?

4. 其他

帶聲音。

php驗證碼類


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 香蕉午夜| 久久青草国产精品一区 | 久久青草免费91线频观看站街 | 亚洲精品国产高清不卡在线 | 欧美性大战久久久久久久蜜桃 | 久久国产精品高清一区二区三区 | 99热久久久这里只有精品免费 | 午夜精品久久久久久 | 99在线视频免费观看 | 狠狠综合欧美综合欧美色 | 日本在线视频精品 | 福利影院在线看 | 国产成人乱码一区二区三区 | 国产精品午夜久久久久久99热 | 欧洲激情乱子伦 | 欧美日韩久久 | 精品久久久久久久免费加勒比 | 久久精品国产精品亚洲人人 | 亚洲欧美在线中文字幕不卡 | 亚洲国产美女精品久久久久 | 狠狠狠狼鲁欧美综合网免费 | 麻豆国产原创最新在线视频 | 国产―笫一页―浮力影院xyz | 99久久久精品免费观看国产 | 中文字幕日韩精品在线 | 国产美女久久久亚洲 | 九九精品在线观看 | 日本不卡免免费观看 | 亚洲狠狠婷婷综合久久久图片 | 波多野结衣免费一区二区三区香蕉 | 精品福利一区 | 日本在线一区二区 | 国产精品入口麻豆午夜 | 免费高清在线影片一区 | 亚洲国产成人精品久久 | 久久综合给会久久狠狠狠 | 精品国产免费一区二区三区 | 日本www在线视频 | 国产成人精品一区二区不卡 | 香蕉成人国产精品免费看网站 | 国产一区亚洲 |