源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

PHP+javascript制作带提示的验证码源码分享

  • 时间:2022-05-05 08:08 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:PHP+javascript制作带提示的验证码源码分享
html代码:
[url=javascript:code()]      <td width="150"  align="center"><div id="yzm1"><font color="#999999">请输入验证码</font></div></td>     </tr>  </table>   </form> </body> </html>
JS代码: yzm.php代码:
[u]复制代码[/u] 代码如下:
<?php header("Content-type: image/png"); $im=imagecreate(66,22);       //创建画布 $black=imagecolorallocate($im,0,0,0);   //定义背景 $white=imagecolorallocate($im,255,255,255);  //定义背景 $gray=imagecolorallocate($im,200,200,200);  //定义背景 imagefill($im,0,0,$gray);      //填充颜色 for($i=0;$i<4;$i++){ //定义4位随机数  $str=mt_rand(1,5);  //定义随机字符所在位置的的Y坐标  $size=mt_rand(6,9); //定义随机字符的字体  $authnum=substr($_GET[num],$i,1);  //获取超级链接中传递的验证码  imagestring($im,$size,(3+$i*15),$str,$authnum,imagecolorallocate($im,rand(0,250),rand(0,250),rand(0,250)));//rand(0,500)数字的模糊程度 }       //水平输出字符串 for($i=0;$i<200;$i++){  //执行for循环,为验证码添加模糊背景   $randcolor=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255)); //创建背景   imagesetpixel($im,rand()%70,rand()%30,$randcolor);  //绘制单一元素 } imagepng($im);    //生成png图像 imagedestroy($im);   //销毁图像 ?>
注意:PHP需要配置才能执行相关方法。 运行效果:
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部