我想让这个脚本中的ImageString(生成一个captcha代码)返回5位数字的captcha码加上文本"is the code"(以帮助混淆垃圾邮件机器人)。我将在哪里修改此代码以在生成的图像中包含我的自定义文本?
谢谢你在这方面的帮助。
<?php
session_start();
$md5_hash = md5(rand(0,99999));
$security_code = substr($md5_hash, 25, 5);
$enc = md5($security_code);
$_SESSION['captcha'] = $enc;
$width = 165;
$height = 30;
$image = ImageCreate($width, $height);
$white = ImageColorAllocate($image, 255, 255, 255);
$black = ImageColorAllocate($image, 0, 0, 0);
$grey = ImageColorAllocate($image, 200, 200, 200);
ImageFill($image, 0, 0, $white);
ImageString($image, 10, 7, 7, $security_code, $black);
header("Content-Type: image/png");
ImagePng($image);
ImageDestroy($image);
?>
也许可以更改
$security_code = substr($md5_hash, 25, 5);
至
$security_code = substr($md5_hash, 25, 5);
$security_code .= " is the code";
这将把您的文本附加到字符串上,然后传递到ImageString()
中。试试这个&看看你怎么样。您可能还需要增加图像宽度。
另一种选择是:如果你的自定义CAPTCHA很弱,你可以使用一个库——它可能更安全,并为你提供更新&随着新版本的发布,提高了安全性。
我使用了SecurImage--http://www.phpcaptcha.org/