|
发表于 2006 年 6 月 21 日 21:31:41
|
显示全部楼层
- <?php
- session_start();
- if($_GET["act"] == "check")
- {
- $_SESSION['login_check_number'] = substr(md5(rand()),20,6);
- for($i=0;$i<5;$i++)
- {
- if(rand(0,1)) $_SESSION['login_check_number'][$i] = strtoupper($_SESSION['login_check_number'][$i]);
- }
- session_register("login_check_number");
- $im = @imagecreate (86, 20)
- or die ("Cannot Initialize new GD image stream");
- $background_color = imagecolorallocate ($im, 200, 200, 200);
- //设置干扰像素,防止被OCR
- for ($i=0;$i<=128;$i++)
- {
- $point_color = imagecolorallocate ($im, rand(0,255), rand(0,255), rand(0,255));
- imagesetpixel($im,rand(2,128),rand(2,38),$point_color);
- }
- //逐个画上验证码字符
- for ($i=0;$i<=5;$i++)
- {
- $text_color = imagecolorallocate ($im, rand(0,255), rand(0,128), rand(0,255));
- $x = 5 + $i * 14;
- $y = rand(1,5);
- imagechar ($im, 5, $x, $y, $_SESSION['login_check_number']{$i}, $text_color);
- }
- //输出PNG图像
- header ("Content-type: image/png");
- imagepng ($im);
- imagedestroy ($im);
- die();
- }
- ?>
复制代码 |
|