触摸屏租赁
Touch screen rental
广告机租赁
Advertising rental
机器人租赁
Robot leasing
 当前位置:首页 > 全部 > PHP验证码刷新方法代码

PHP验证码刷新方法代码

xym.php

<?php
srand((double)microtime()*1000000);//设置随机数的种子
$im=imagecreate(45,18);//创建一个画布
$black=imagecolorallocate($im,0,0,0);//定义画布颜色为黑色
$white=imagecolorallocate($im,255,255,255);//定义画布颜色为白色
$gray=imagecolorallocate($im,200,200,200);//定义画布颜色为灰色
imagefill($im,0,0,$gray);//用灰色填充画布
session_register("autonum");//注册SESSION变量
$_SESSION["autonum"]="";//初始化SESSION变量
for($i=0;$i<4;$i++){
$str=mt_rand(1,3);//设置随机的字体
$size=mt_rand(3,6);//设置随机的字符大小
$authnum=mt_rand(0,9);//设置字符为随机的数字0-9
$_SESSION["autonum"].=$authnum;
imagestring($im,$size,(5+$i*10),$str,$authnum,imagecolorallocate($im,rand(0,130),rand(0,130),rand(0,130)));
}
for($i=0;$i<200;$i++){
$randcolor=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));//为图像分配颜色即设置字符的颜色
imagesetpixel($im,rand()%70,rand()%30,$randcolor); //在画布上画一个点
}
imagepng($im);//生成PNG格式的图像
imagedestroy($im);//释放图像资源
?>

 

用法:
<script language="javascript" type="text/javascript">
function RefreshImage()
{
var el =document.getElementById("img11");
el.src=el.src+'?';//这个特别重要
}
</script>

<form method="post" action="admin_login_check.php" name="logform">

<p>
<label>验证码:</label>
<input name="xym" type="text" size="8" />
&nbsp;&nbsp;<img id="img11" src="xym.php" style="cursor:pointer" onmouseup="RefreshImage()" alt="点击刷新" title="点击刷新" /><span>点击图片刷新</span>

</p>

 

 


工作室地址:重庆石桥铺电脑城B座 | 微信:z35544216 | 网址:www.35544216.com