<?php
/******************************************
* Created on Dec 28, 2008
*
* Project : LEAPJ
* FileName : verifyCode.php
* Author : Leacen
* Version : 0.0.1
* Copyright: Scweb Network Studio, Inc.
*/ $image = imagecreatetruecolor(90,30);
session_start();
$_SESSION[ "verify "] = " "; $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
$str = "abcdefghijklmnopqrstuvwxyz0123456789 ";
imagefill($image,0,0,$white); $verifyLen = 4;
$verifyCode = " "; for($i = 0; $i < 100; $i++){
$color = imagecolorallocate($image,rand(180,255),rand(180,255),rand(180,255));
//imagearc($image,rand(0,imagesx($image)),rand(0,imagesy($image)),rand(0,5),rand(0,5),0,rand(0,360),$color);
imageline($image,rand(0,imagesx($image)),rand(0,imagesy($image)),rand(0,imagesx($image)),rand(0,imagesy($image)),$color);
} for($i = 0; $i < $verifyLen; $i++){
$color = imagecolorallocate($image,rand(0,150),rand(0,150),rand(0,150));
$tmpIndex = rand(0,strlen($str)-1);
$verifyCode .= $str[$tmpIndex];
@imagettftext($image, 20, rand(-15,15), $i*20+10,25,$color, 'Verdana.ttf ', $str[$tmpIndex]) or imagechar($image,5,$i*10+3,1,$str[$tmpIndex],$color);; }
$_SESSION[ "verify "] = $verifyCode; header( 'Content-type: image/png ');
imagepng($image);
imagedestroy($image); ?>
/******************************************
* Created on Dec 28, 2008
*
* Project : LEAPJ
* FileName : verifyCode.php
* Author : Leacen
* Version : 0.0.1
* Copyright: Scweb Network Studio, Inc.
*/ $image = imagecreatetruecolor(90,30);
session_start();
$_SESSION[ "verify "] = " "; $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
$str = "abcdefghijklmnopqrstuvwxyz0123456789 ";
imagefill($image,0,0,$white); $verifyLen = 4;
$verifyCode = " "; for($i = 0; $i < 100; $i++){
$color = imagecolorallocate($image,rand(180,255),rand(180,255),rand(180,255));
//imagearc($image,rand(0,imagesx($image)),rand(0,imagesy($image)),rand(0,5),rand(0,5),0,rand(0,360),$color);
imageline($image,rand(0,imagesx($image)),rand(0,imagesy($image)),rand(0,imagesx($image)),rand(0,imagesy($image)),$color);
} for($i = 0; $i < $verifyLen; $i++){
$color = imagecolorallocate($image,rand(0,150),rand(0,150),rand(0,150));
$tmpIndex = rand(0,strlen($str)-1);
$verifyCode .= $str[$tmpIndex];
@imagettftext($image, 20, rand(-15,15), $i*20+10,25,$color, 'Verdana.ttf ', $str[$tmpIndex]) or imagechar($image,5,$i*10+3,1,$str[$tmpIndex],$color);; }
$_SESSION[ "verify "] = $verifyCode; header( 'Content-type: image/png ');
imagepng($image);
imagedestroy($image); ?>
解决方案 »
- eval(function(p,a,c,k,e,d)的加密和解密程序,看不懂,也不知道怎么用
- 页面上点击图片链接会弹出另一个页面悬浮在当前页上面 之后点击关闭后可以返回当前页面
- 用jquery或Js 如何实现【选项卡】功能
- 多选框写入数据库问题
- js能不能直接调用asp生成的数组变量?
- undo和setTimeout冲突哦
- 一个很菜的问题? 急!!请各位高手帮忙!
- 大家帮帮我,这样的js怎样写啊,明天要用的,急求!!!!!!
- 求一函数,在线等.......
- 本人想学JAVASCRIPT,苦于不知如何入门,请各位大侠指点一二,希望书不会太厚,谢谢.
- 有针对.net的JavaScript框架吗?针对.NET应该学习怎么的JavaScript框架呢?请详细解答一下,谢谢
- JS 遍历头字母添加滚动条
session_start();
header("content-type:image/png"); //设置创建图像的格式
$image_width=70; //设置图像宽度
$image_height=18; //设置图像高度
srand(microtime()*100000); //设置随机数的种子
for($i=0;$i<4;$i++){ //循环输出一个4位的随机数
$new_number.=dechex(rand(0,15));
}
$_SESSION[check_checks]=$new_number; //将获取的随机数验证码写入到SESSION变量中 $num_image=imagecreate($image_width,$image_height); //创建一个画布
imagecolorallocate($num_image,255,255,255); //设置画布的颜色
for($i=0;$i<strlen($_SESSION[check_checks]);$i++){ //循环读取SESSION变量中的验证码
$font=mt_rand(3,5); //设置随机的字体
$x=mt_rand(1,8)+$image_width*$i/4; //设置随机字符所在位置的X坐标
$y=mt_rand(1,$image_height/4); //设置随机字符所在位置的Y坐标
$color=imagecolorallocate($num_image,mt_rand(0,100),mt_rand(0,150),mt_rand(0,200)); //设置字符的颜色
imagestring($num_image,$font,$x,$y,$_SESSION[check_checks][$i],$color); //水平输出字符
}
imagepng($num_image); //生成PNG格式的图像
imagedestroy($num_image); //释放图像资源
?>这个也够简单的了