<?php
//============================
// Filename: imgcode.php
// Version : 0.0.2
// Author  : leo
// Update  : 2008-1-30
// Content : 4位数字验证码生成器
//  使用方法: <img src="imgcode.php" style="cursor:pointer;" OnClick="this.src+='?'+Math.floor(Math.random()*10);" alt="点击刷新" />
//  判断方法: $_POST['checkcode']!=$_SESSION['imgcode']?'No':'Yes';
//============================
session_start(); //启用session
$_SESSION['imgcode']=mt_rand(1000,9999); //4位随机数$im=@imagecreate(38,15) or die(1); //创建一个(38*15)图像
imagecolorallocate($im,mt_rand(192,255),mt_rand(192,255),mt_rand(192,255));
imagestring($im,5,2,0,$_SESSION['imgcode'],imagecolorallocate($im,mt_rand(0,193),mt_rand(0,193),mt_rand(0,193))); //设定图像:字体5,内容:四位随机数,坐标:(2,0)
for($i=0;$i<64;$i++)imagesetpixel($im,mt_rand(0,38),mt_rand(0,15),imagecolorallocate($im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255))); //填充header("Content-type:image/png"); //设定为以PNG格式
imagepng($im); //绘制输出
imagedestroy($im); //释放图片内存
?>

解决方案 »

  1.   

    还是要多动手,GOOGLE一下很多例子。范例:http://www.phpchina.com/html/200606/n983.html
    这个不是很难,自己动手也能写出不错的CODE
      

  2.   

    a.php<? 
    session_start(); 
    function random($len) 

    $srcstr="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; 
    mt_srand(); 
    $strs=""; 
    for($i=0;$i<$len;$i++){ 
    $strs.=$srcstr[mt_rand(0,35)]; 

    return strtoupper($strs); 

    $str=random(4); //随机生成的字符串 
    $width = 50; //验证码图片的宽度 
    $height = 25; //验证码图片的高度 
    @header("Content-Type:image/png"); 
    $_SESSION["code"] = $str; 
    $im=imagecreate($width,$height); 
    //背景色 
    $back=imagecolorallocate($im,0xFF,0xFF,0xFF); 
    //模糊点颜色 
    $pix=imagecolorallocate($im,187,230,247); 
    //字体色 
    $font=imagecolorallocate($im,41,163,238); 
    //绘模糊作用的点 
    mt_srand(); 
    for($i=0;$i<1000;$i++) 

    imagesetpixel($im,mt_rand(0,$width),mt_rand(0,$height),$pix); 

    imagestring($im, 5, 7, 5,$str, $font); 
    imagerectangle($im,0,0,$width-1,$height-1,$font); 
    imagepng($im); 
    imagedestroy($im); 
    $_SESSION["code"] = $str;
    ?>b.php
    <?php 
    session_start(); 
    echo "<img src=a.php border=0 align=absbottom>";//生成图片 
    //echo $_SESSION["code"];//生成验证码值 
    ?>
    运行b.php就可,
    (jf)
      

  3.   

    你在html页面引用img 标签的时候这样 写<img src = "../a.php">把php的文件当成gif的文件一样的。就可以看到验证马了