首页 技术 正文
技术 2022年11月15日
0 收藏 462 点赞 2,544 浏览 1241 个字

使用php生成动态的验证码图片

 <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>GETTING STARTED WITH BRACKETS</title>
<style>
img{vertical-align: bottom;}
</style>
</head>
<body>
<h2>PHP中的函数</h2>
<?php
function add($a,$b){
$sum = 0;
$sum = $a+$b;
return $sum;
}
echo add(1,2);
?>
<hr/>
<?php
$s = 'abc';
echo $s[1];//b
?>
<h2>使用PHP生成动态的验证码图片</h2>
<?php ?>
<hr/>
<h2>用户登录</h2>
用5-1.php语言脚本生成我需要的图片,是服务器端动图生成的图片
验证码:<input/><img src="5-1.php"/>
</body>
</html>

index.php

<?php
//注意,此文件是要向客户端输出一副动态生成的图片,所以,前前后后不能有任何的字符输出 //告诉客户端,本页面输出的内容类型,是一个图片
header('Content-Type','image/png');
$w = 100;
$h = 30;//在服务器的内存中创建一副真彩色图片
$img = imagecreatetruecolor($w,$h);//分配一个即将使用的颜色(固定颜色)
// $c=imagecolorallocate($img,255,0,0);//红色//分配一个即将使用的颜色(随机颜色)
$c=imagecolorallocate($img,rand(150,230),rand(150,230),rand(150,230));//在图片上画一个矩形,作为背景色
imagefilledrectangle($img,0,0,$w,$h,$c);//生成四个随机的字符
$src = 'ABCDEFGHIJKLMNPQRSTUVXWYZ23456789';//除去字母O和数字0,1,容易混淆
$txt = $src[rand(0,strlen($src))];
$txt .= $src[rand(0,strlen($src))];
$txt .= $src[rand(0,strlen($src))];
$txt .= $src[rand(0,strlen($src))];//再重新分配一个颜色
$c=imagecolorallocate($img,rand(150,230),rand(150,230),rand(150,230));//把字符串刷到图片上
imagestring($img,20,30,8,$txt,$c);//向客户端输出图片中的二进制数据
imagepng($img);//从服务器端的内存中删除创建的图片
imagedestroy($img);
?>
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,087
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,562
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,412
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,185
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,821
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905