图形随机码的生成。。

图形随机码的生成。。

效果:



[复制到剪切板]
CODE:
<?php

$im 
imagecreate(4825);
    
    
$backgroundcolor imagecolorallocate ($im255255255);
    
$black imagecolorallocate($im,100,100,100);
    
$bordercolor imagecolorallocate($im 150150150);
    
    
//debug 增加图片的掺杂特性
    
$linenums mt_rand(1032);
    for(
$i=0$i <= $linenums$i++) {
        
$linecolor imagecolorallocate($immt_rand(0255), mt_rand(0255), mt_rand(0255));
        
$linex mt_rand(048);
        
$liney mt_rand(025);
        
imageline($im$linex$liney$linex mt_rand(04) - 2$liney mt_rand(04) - 2$linecolor);
    }    
    
    for(
$i=0$i <= 64$i++) {
        
$pointcolor imagecolorallocate($immt_rand(50255), mt_rand(50255), mt_rand(50255));
        
imagesetpixel($immt_rand(048), mt_rand(025), $pointcolor);
    }
    
    
$string "";
      
$arr = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','a','b');//把想要码的填进来
      
srand((double) microtime()*10000000);
      
$randcode array_rand($arr,4);
      for(
$i=0;$i<4;$i++){//生成4位随机数
      
$string .= $arr[$randcode[$i]];
      }

    
    
imagerectangle($im004724$bordercolor);
    
imagestring($im,7,4,4,$string,$black);    
    
//debug 合成图片
    
header('Content-type: image/png');
    
imagepng($im);
    
imagedestroy($im);

?> ;

如履薄冰

Fatal error: imagepng(): gd-png: fatal libpng error: Incompatible libpng version in application and library in /usr/local/apache2/htdocs/test/upsub.php on line 83
应用时倒数第二行imagepng($im);出现上述错误提示

你的php没有自带GD库阿
如履薄冰

srand((double) microtime()*10000000); 这一行不是明白是什么意思,只知道是用来生成生成随机数种子,哪位高手帮帮小弟解释一下。

请问怎么调用

把以上代码写要code.php里,然后在你想生成随机码的地方,比如index.php里你要显示这个验证码的地方添加一个img
<img src="code.php" name="name" id="id">

我的意思是
如何
用表单里的
<input type=text name="yanzheng"><img src="code.php">
表单中的$yanzheng和code.php验证码中的哪个变量比较
才能判断呢?
谢谢回复!!

hehe.

引用:
原帖由 wudeyong 于 2006-7-29 15:42 发表
我的意思是
如何
用表单里的
<input type=text name="yanzheng"><img src="code.php">
表单中的$yanzheng和code.php验证码中的哪个变量比较
才能判断呢?
谢谢回复!!
和 $sting (最后生成的四个数字)比较啊

再来一个小顶!