PHP的数字Captcha

Ada*_*nch 5 php captcha numbers

是否有可用于PHP数字验证码?

(不依赖于JavaScript打开)


编辑:

  • 我知道那里有独立于JS的验证码.
  • 我知道那里有PHP验证码.
  • 我知道那里有数字验证码.

但我正在寻找一个PHP数字Javascript独立验证码.
我发现的唯一数字验证码是ASP.NET或基于jQuery/JS的.
我不希望其中任何一个作为问题的答案.

我不是在这里拿一个小网站.在答案中,我想知道你的建议是否给服务器带来了很大压力.

tra*_*lix 16

我想在处理验证码时处理渲染图像是不可避免的?这是一个简单的(可能不是最优雅的):

样本输出

session_start();

$strings = '123456789';
$i = 0;
$characters = 6;
$code = '';
while ($i < $characters)
{ 
    $code .= substr($strings, mt_rand(0, strlen($strings)-1), 1);
    $i++;
} 

$_SESSION['captcha'] = $code;

//generate image
$im = imagecreatetruecolor(124, 40);
$foreground = imagecolorallocate($im, 0, 0, 0);
$shadow = imagecolorallocate($im, 173, 172, 168);
$background = imagecolorallocate($im, 255, 255, 255);

imagefilledrectangle($im, 0, 0, 200, 200, $background);

// use your own font!
$font = 'monofont.ttf';

//draw text:
imagettftext($im, 35, 0, 9, 28, $shadow, $font, $code);
imagettftext($im, 35, 0, 2, 32, $foreground, $font, $code);     

// prevent client side  caching
header("Expires: Wed, 1 Jan 1997 00: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");

//send image to browser
header ("Content-type: image/png");
imagepng($im);
imagedestroy($im);
Run Code Online (Sandbox Code Playgroud)

以表格形式显示:

<img src="captcha.php">
Enter the code above: <input type="text" name="captcha">
Run Code Online (Sandbox Code Playgroud)

提交后,检查输入的代码:

if ($_POST['captcha'] == $_SESSION['captcha'])
    // do your thing
Run Code Online (Sandbox Code Playgroud)