Heim  >  Artikel  >  php教程  >  简单实例php验证码代码

简单实例php验证码代码

WBOY
WBOYOriginal
2016-05-25 16:42:351267Durchsuche

验证码,是一种区分用户是计算机和人的公共全自动程序,在captcha测试中,作为服务器的计算机会自动生成一个问题由用户来解答,这个问题可以由计算机生成并评判,但是必须只有人类才能解答,由于计算机无法解答captcha的问题,所以回答出问题的用户就可以被认为是人类,php实例代码如下:

<?php
session_start();
$string = null;
$im = imagecreatetruecolor(60, 25); //创建真彩图60*25
$bg = imagecolorallocate($im, 255, 255, 255); //白色背景
imagefill($im, 0, 0, $bg); //填充白色
$x = 5; //
$y = 0; //文字坐标
for ($i = 0; $i & lt; 4; $i++) {
    $char = mt_rand(0, 9);
    $string.= $char;
    $y = mt_rand(0, 10);
    $ccolor = imagecolorallocate($im, mt_rand(0, 230) , mt_rand(0, 230) , mt_rand(0, 230));
    imagechar($im, 6, $x, $y, $char, $ccolor); //填充文字
    $x+= mt_rand(10, 15);
}
for ($i = 0; $i{$x1 = mt_rand(0, 80); $x2 = mt_rand(0, 80); $y1 = mt_rand(0, 30); $y2 = mt_rand(0, 30); $x2 = $x1 + mt_rand(1, 5); $y2 = $y1 + mt_rand(1, 5); $lc = imagecolorallocate($im, mt_rand(0, 230) , mt_rand(0, 230) , mt_rand(0, 230)); imageline($im, $x1, $y1, $x2, $y2, $lc); //填充线条
}$_session[&#39;code&#39;] = md5($string); header("content-type:image/jpeg"); imagepng($im); imagedestroy($im);


永久地址:

转载随意~请带上教程地址吧^^

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn