文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>图形认证

图形认证

时间:2007-02-18  来源:PHP爱好者

CODE:
[复制到剪切板]
<?php
//
// +----------------------------------------------------------------------+
// | PHP version 4.0                                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 2004                                                   |
// | Beijing Innovative Linkage Tech Ltd.                                 |
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Authors: 佟杰义<[email protected]>                                    |
// +----------------------------------------------------------------------+
//
// $Id: vImage.inc.php
//

/**
*
* @version  v 1.0
* @author   佟杰义<[email protected]>
* @access   Public
*/


/**
 * 图形的验证码的类(显示,传递验证码)
 */

class validateImage
{

    var $x;
    var $y;
    var $numChars;
    var $Code;
    var $Width;
    var $Height;
    var $BG;
    var $colTxt;
    var $colBorder;
    var $numCirculos;

    function validateImage()
    {
        $this->x = $x;
        $this->y = $y = "6";
        $this->numChars = $numChars = "4";
        $this->Code = $Code;
        $this->Width = $Width = "80";
        $this->Height = $Height = "25";
        $this->BG = $BG = "255 255 255";
        $this->colTxt = $colTxt = "0 0 0 0";
        $this->Border = $colBorder = "100 100 100";
        $this->numCirculos = $numCirculos = "800";
    }

    //Create base Image
    function createImage()
    {
        //Create a image
        $im = imagecreate ($this->Width, $this->Height) or die ("Cannot Initialize new GD image stream");

        //Get the RGB color code
        $colorBG = explode(" ", $this->BG);

        $colorBorder = explode(" ", $this->Border);

        $colorTxt = explode(" ", $this->colTxt);

        //put the background color on the image
        $imBG = imagecolorallocate ($im, $colorBG[0], $colorBG[1], $colorBG[2]);

        //put the border on the image
        $Border = ImageColorAllocate($im, $colorBorder[0], $colorBorder[1], $colorBorder[2]);
        $imBorder = ImageRectangle($im, 0, 0, $this->Width-1,$this->Height-1, $Border);

        //put the code color on the image
        $imTxt = imagecolorallocate ($im, $colorTxt[0], $colorTxt[1], $colorTxt[2]);

        //Drop 800 points
        for($i = 0; $i < $this->numCirculos; $i++)
        {
            $imPoints = imagesetpixel($im, mt_rand(0,80), mt_rand(0,80), $Border);
        }

        //put the Code on image
        for($i = 0; $i < $this->numChars; $i++)
        {
            //get $x's location
            $this->x = 21 * $i;

            //get the code
            $this->Code.= (mt_rand(0,10));

            $putCode = substr($this->Code, $i, "1");

            //put the code;
            $Code = imagestring($im, 5, $this->x, $this->y, $putCode,$imTxt);

        }

        return $im;

    }


    //Transfer the code to next page
    function transferCode()
    {
        //get the code
        $this->createImage();
        $vCode = $this->Code;

        return $vCode;
    }


    //display the image
    function show()
    {
        header("Content-type:image/png");
        Imagepng($this->createImage());
        Imagedestroy($this->createImage());
    }

}

if($HTTP_GET_VARS["show"] == "true")
{
    //use and show it
    $im = new validateImage;

    $im->show();
}

?>  php爱好者站 http://www.phpfans.net c/vc/c++/java.
上面的存为 vImage.inc.php
在同级目录,新建立个文件
CODE:
[复制到剪切板]
<?php

/*
*这里放session类
*/

session_start();
session_register(vCode);


include_once("vImage.inc.php");

//use and test it
$im = new validateImage;

$vCode = $im->transferCode();


?>
<HTML>
<HEAD>
<TITLE> test </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<BODY>

<img src = "vImage.inc.php?show=true">

</BODY>
</HTML>  php爱好者站 http://www.phpfans.net php动态|php基础|php进阶|php模板.
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载