code.php,code.php

/*

*/

session_start();//开启session

$randval;

for($i = 0; $i<4; $i++){

//产生A-Z之间的ASCII随机数

$randstr = mt_rand(ord('A'), ord('Z'));//ord($str)返回字符的ASCII

$randv = mt_rand(0, 10);//包括0和10

global $randval;

//产生0-9之间的随机数

if($randv % 2 == 0){//如果是偶数,连接数字

$randval .= mt_rand(0, 9);

}else{//否则奇数连接字符,用chr获取

$randval .= chr($randstr);//chr()返回相对应于 ascii 所指定的单个字符。

}

}

$_SESSION["randval"] = $randval;

$intheight = 18;//验证码背景图的高

$intwidth = 51;//验证码背景图的宽,可相应修改

$img = imagecreatetruecolor($intwidth, $intheight);

$fontcolor = imagecolorallocate($img, 255, 0, 0);

$backcolor = imagecolorallocate($img, 255, 255, 255);

imagefill($img, 0, 0, $backcolor);

//画线

//imageline($img, mt_rand(0,$intwidth/3), mt_rand(0,$intheight/3), mt_rand($intwidth/3,$intwidth), mt_rand($intheight/3,$intheight), $fontcolor);

//imageline($img, mt_rand($intwidth/3, $intwidth), mt_rand(0, $intheight/3), mt_rand(0, $intwidth/3), mt_rand(0, $intheight/3), $fontcolor);

//添加img里边的文字信息

imagestring($img, 10, mt_rand(0, $intwidth - strlen($randval) * 10), mt_rand(0, $intheight-15), $randval, $fontcolor);

imagegif($img);

imagedestroy($img);

?>

一键复制

编辑

Web IDE

原始数据

按行查看

历史

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值