Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 是否向验证码图像添加其他噪声?_Php_Captcha_Gdlib - Fatal编程技术网

Php 是否向验证码图像添加其他噪声?

Php 是否向验证码图像添加其他噪声?,php,captcha,gdlib,Php,Captcha,Gdlib,我有这个简单的在线验证码脚本。我喜欢它,我编辑它,以适应我的网站,但不知道是否有人可以编辑它添加一些随机线验证码本身,因为它有点太简单了 我确实找到了关于如何做这件事的教程,但它对我不起作用 下面是简单的验证码脚本;我想修改它,使一些随机线出现在验证码上: $width = 150; $height = 24; $length = 5; $font = 'caviardreams.ttf'; $font_size = 14; $bg_

我有这个简单的在线验证码脚本。我喜欢它,我编辑它,以适应我的网站,但不知道是否有人可以编辑它添加一些随机线验证码本身,因为它有点太简单了

我确实找到了关于如何做这件事的教程,但它对我不起作用

下面是简单的验证码脚本;我想修改它,使一些随机线出现在验证码上:

   $width    = 150;
   $height   = 24;
   $length   = 5;
   $font     = 'caviardreams.ttf';
   $font_size   = 14;
   $bg_color = array(245, 245, 245);
   $chars    = 'ABCDEFGHKMNPQRSTUVWXYZ23456789';
   session_start();
   //putenv('GDFONTPATH=' . realpath('.'));
   $img = imagecreatetruecolor($width, $height);
   $bkgr = imagecolorallocate($img, $bg_color[0], $bg_color[1], $bg_color[2]);
   imagefilledrectangle($img, 0, 0, $width, $height, $bkgr);

   $code = '';
   for($i = 0; $i < $length; $i++)
   {
      $code .= $chr = $chars[mt_rand(0, strlen($chars)-1)];
      $r = rand(0, 192);
      $g = rand(0, 192);
      $b = rand(0, 192);
      $color = imagecolorallocate($img, $r, $g, $b);
      $rotation = rand(-35, 35);
      $x = 5+$i*(4/3*$font_size+2);
      $y = rand(4/3*$font_size, $height-(4/3*$font_size)/2);
      imagettftext($img, $font_size, $rotation, $x, $y, $color, $font, $chr);
   }

   $_SESSION['random_txt'] = md5($code);

   header("Content-type: image/png");
   header("Expires: Mon, 01 Jul 1998 05:00:00 GMT");
   header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
   header("Cache-Control: no-store, no-cache, must-revalidate");
   header("Cache-Control: post-check=0, pre-check=0", false);
   header("Pragma: no-cache");

   imagepng($img);
   imagedestroy($img);
$width=150;
$height=24;
$length=5;
$font='caviardreams.ttf';
$font_size=14;
$bg_color=array(245245245245);
$chars='ABCDEFGHKMNPQRSTUVWXYZ23456789';
会话_start();
//putenv('GDFONTPATH='.realpath('.');
$img=ImageCreateTureColor($width,$height);
$bkgr=imagecolorallocate($img、$bg_color[0]、$bg_color[1]、$bg_color[2]);
imagefilledrectangle($img,0,0,$width,$height,$bkgr);
$code='';
对于($i=0;$i<$length;$i++)
{
$code.=$chr=$chars[mt_rand(0,strlen($chars)-1)];
$r=兰特(0192);
$g=兰特(0192);
$b=兰特(0192);
$color=imagecolorallocate($img,$r,$g,$b);
$rotation=兰特(-35,35);
$x=5+i*(4/3*$font\U size+2);
$y=兰特(4/3*$font\U size,$height-(4/3*$font\U size)/2);
imagettftext($img、$font_size、$rotation、$x、$y、$color、$font、$chr);
}
$\会话['random\u txt']=md5($code);
标题(“内容类型:图像/png”);
标题(“到期日期:1998年7月1日星期一05:00:00 GMT”);
标题(“上次修改:”.gmdate(“D,D M Y H:i:s”)“GMT”);
标头(“缓存控制:无存储,无缓存,必须重新验证”);
标头(“缓存控制:后检查=0,预检查=0”,false);
标题(“杂注:无缓存”);
图像PNG($img);
图像处理(img);

如果您想继续使用该脚本,您可以查看源代码并找出设计模式是如何实现的。抱歉,如果这不是您要寻找的答案。我想重点介绍的部分是:

/* generate random lines in background */
/* generate random dots in background */
这两项似乎都是你想要做的事情

就在:

$_SESSION['random_txt'] = md5($code);
插入:

for ($i=0;$i<100;$i++)
  imageline($img,mt_rand(0,$width),mt_rand(0,$height),mt_rand(0,$width),mt_rand(0,$height),imagecolorallocate($img,rand(0,63),rand(0,63),rand(0,63)));

用于($i=0;$i为什么不仅仅使用一个已经制作好并免费使用的验证码脚本?它被称为
recpatcha
,并且可以从中获得:嗨,我一直使用recaptcha,但我现在不喜欢它,我不喜欢这样一个事实:如果用户禁用javascript,它会在网页上显示糟糕的内容,而且会很笨拙,因此我放弃了recaptcha a在使用了大约2年后,我重新设计了我的网站,但它并不适合我的网站,另外我还用验证码实现了另外两种方法来帮助防止垃圾邮件。我只是想找人修改代码,为我添加随机行,如果他们不介意的话,我不想使用任何其他脚本,我想保留这一行它很简单,没有陷入困境。感谢使用SecurImage PHP验证码。它在GD上运行良好,不需要javascript:您好,正如我所说,我不想使用任何其他脚本。谢谢,我不是在问这个问题,我不想听起来粗鲁,但我问是否有人可以帮我修改它,不要建议验证码脚本,我已经知道了,谢谢我仍然站着,非常感谢你的时间和帮助:)非常感谢!