php生成验证码并显示在浏览器
来源:互联网 发布:wps网络受限 编辑:程序博客网 时间:2024/06/04 19:36
php文件名是image.func.php
<?php session_start();// //创建画布$width=80;$height=28;$image=imagecreatetruecolor($width, $height);//返回以画像,默认黑色$white=imagecolorallocate($image,255,255,255);//为画布上色$black=imagecolorallocate($image,0,0,0);//为画布上色// //用填充矩形填充画布//imagefilledrectangle()意思是在$image画布上画了一个$white颜色的矩形,其左上角坐标为 x1,y1,右下角坐标为 x2,y2。0, 0 是图像的最左上角。并无返回数据imagefilledrectangle($image, 0, 0, $width, $height, $white);$chars=buildRandomString($type,$length);$_SESSION[$sess_name]=$chars;$fontfiles=array("msyh.ttc","msyhbd.ttc","msyhl.ttc","simsun.ttc");for ($i=0; $i <$length ; $i++) { //mt_rand()生成x到y范围内随机数$size=mt_rand(14,18);$angle=mt_rand(-15,15);$x=5+$i*$size;$y=mt_rand(20,26);$color=imagecolorallocate($image,mt_rand(50,90),mt_rand(80,200),mt_rand(90,180));$fontfile="../fonts/".$fontfiles[mt_rand(0,count($fontfiles)-1)];$text=substr($chars,$i,1);//向图像写入文本imagettftext($image,$size,$angle,$x,$y,$color,$fontfile,$text);}if ($pixel) {for ($i=0; $i < 50; $i++) { //imagesetpixel() 在 image 图像中用 color 颜色在 x,y 坐标(图像左上角为 0,0)上画一个点。imagesetpixel($image,mt_rand(0,$width-1),mt_rand(0,$height-1),$black);}}if ($line) {for ($i=1; $i < $line; $i++) { $color=imagecolorallocate($image,mt_rand(50,90),mt_rand(80,200),mt_rand(90,180));//imageline() 用 color 颜色在图像 image 中从坐标 x1,y1 到 x2,y2(图像左上角为 0, 0)画一条线段。imageline($image,mt_rand(0,$width-1),mt_rand(0,$height-1),mt_rand(0,$width-1),mt_rand(0,$height-1),$color);}}header("content-type:image/png");//imagegif — 输出图象到浏览器或文件。// imagegif($image);imagepng($image);imagedestroy($image);?>
html代码
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Document</title></head><body><img src="http://localhost/PHPDemo/lib/image.func.php" onclick="getVerify()" id="verify"><script src="https://cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script><script type="text/javascript">function getVerify() {$("#verify").attr("src","http://localhost/PHPDemo/lib/image.func.php");}</script></body></html>
0 0
- php生成验证码并显示在浏览器
- 生成验证码并在页面进行显示
- PHP生成图片缩略图,并在浏览器中显示,灵活,实用
- php中文验证码不显示文字的原因-终端下可正常生成图片,在浏览器中没有文字只有底图
- PHP实现提取一个图像文件并显示在浏览器上
- asp.net2.0生成验证码,并显示验证码
- asp.net2.0生成验证码,并显示验证码
- php 生成图片验证码 并表单验证
- php 生成图片验证码,并表单验证
- 用servlet在网页生成验证码并验证
- php 验证码 在页面正常显示
- php验证码在服务器不显示
- 生成验证码并验证
- 使用struts2生成图片验证码并显示
- 如何解决php 生成验证码图片不显示问题
- php生成的验证码图片不显示问题
- PHP生成验证码
- PHP 生成验证码
- OpenJudge-Mooc 323:棋盘问题(dfs)
- iOS之两圆之间标准圆的随机生成
- ubuntu 14.04 安装jekyll
- jsp访问mysql数据库方式
- 关于vitualbox报错
- php生成验证码并显示在浏览器
- 第三章 JavaScript 栈
- jQuery Json数组操作
- EDA软件_Cadence_OrCAD Capture创建新元器件
- linux 相关整理
- Android的加载动画AVLoadingIndicatorView
- lombok介绍
- redis集群设置密码详解
- mysql/maridb多实例安装