导航:首页 > 编程语言 > php验证码源代码

php验证码源代码

发布时间:2022-10-18 23:32:44

php网页不显示验证码,以下是源代码,请高手指点

img 标签的src怎么回事html文件,应该是生成图片代码的连接吧。

㈡ 求一个php登录代码,有验证码功能,能答必采纳。

<?php
Header("Content-type: image/gif");
$border = 1;
$how = 4;
$w = $how*15;
$h = 20;
$fontsize = 10;
$alpha = "abcdefghijkmnopqrstuvwxyz";
$number = "023456789";
$randcode = "";
srand((double)microtime()*1000000);
$im = ImageCreate($w, $h);
$bgcolor = ImageColorAllocate($im, 255, 255, 255);
ImageFill($im, 0, 0, $bgcolor);
if($border)
{
$black = ImageColorAllocate($im, 0, 0, 0);
ImageRectangle($im, 0, 0, $w-1, $h-1, $black);
}
for($i=0; $i<$how; $i++)
{
$alpha_or_number = mt_rand(0, 1);
$str = $alpha_or_number ? $alpha : $number;
$which = mt_rand(0, strlen($str)-1);
$code = substr($str, $which, 1);
$j = !$i ? 4 : $j+15;
$color3 = ImageColorAllocate($im, mt_rand(0,100), mt_rand(0,100), mt_rand(0,100));
ImageChar($im, $fontsize, $j, 3, $code, $color3);
$randcode .= $code;
}
for($i=0; $i<5; $i++)
{
$color1 = ImageColorAllocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
ImageArc($im, mt_rand(-5,$w), mt_rand(-5,$h), mt_rand(20,300), mt_rand(20,200), 55, 44, $color1);
}
for($i=0; $i<$how*40; $i++)
{
$color2 = ImageColorAllocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
ImageSetPixel($im, mt_rand(0,$w), mt_rand(0,$h), $color2);
}
session_start();
$_SESSION['randcode'] = $randcode;
Imagegif($im);
ImageDestroy($im);
?>

以上是随机生成验证码的代码,加入保存为yz.php,则使用时只需,<img src="yz.php">

<?php
session_start();
if($_SESSION['randcode'] = $_POST['yzm']){
echo '验证码错误'
exit;
}else{
$sql = "SELECT id FROM table WHERE yhm = '".$_POST['yhm']."' AND mm = '".$_POST['mm']."'";
$result = mysql_query($sql);
if($result){
echo '<meta http-equiv="refresh" content="0;url=index.html"/>'
exit;
}else{
echo '账号或密码错误'
exit;
}
}
?>

比较简单,懂的应该都懂

㈢ php的图片验证码代码

这个是phpcms的验证码,经过十几万个网站经验的,非常好用
<?php

session_start();

$enablegd = 1;
//判断图像处理函数是否存在
$funcs = array('imagecreatetruecolor','imagecolorallocate','imagefill','imagestring','imageline','imagerotate','imagedestroy','imagecolorallocatealpha','imageellipse','imagepng');
foreach($funcs as $func)
{
if(!function_exists($func))
{
$enablegd = 0;
break;
}
}

ob_clean(); //清理缓冲

if($enablegd)
{
//create captcha
$consts = 'cdfgkmnpqrstwxyz23456';
$vowels = 'aek23456789';
for ($x = 0; $x < 6; $x++)
{
$const[$x] = substr($consts, mt_rand(0,strlen($consts)-1),1); //获取$consts中的一个随机数
$vow[$x] = substr($vowels, mt_rand(0,strlen($vowels)-1),1); //获取$vowels中的一个随机数
}
$radomstring = $const[0] . $vow[0] .$const[2] . $const[1] . $vow[1] . $const[3] . $vow[3] . $const[4];
$_SESSION['checkcode'] = $string = substr($radomstring,0,4); //显示4个字符

$imageX = strlen($radomstring)*8; //图像的宽
$imageY = 20; //图像的高
$im = imagecreatetruecolor($imageX,$imageY); //新建一个真彩色图像

//creates two variables to store color
$background = imagecolorallocate($im, rand(180, 250), rand(180, 250), rand(180, 250)); //背景色
$foregroundArr = array(imagecolorallocate($im, rand(0, 20), rand(0, 20), rand(0, 20)),
imagecolorallocate($im, rand(0, 20), rand(0, 10), rand(245, 255)),
imagecolorallocate($im, rand(245, 255), rand(0, 20), rand(0, 10)),
imagecolorallocate($im, rand(245, 255), rand(0, 20), rand(245, 255))
);
$foreground2 = imagecolorallocatealpha($im, rand(20, 100), rand(20, 100), rand(20, 100),80); //分配颜色并说明透明度
$middleground = imagecolorallocate($im, rand(200, 160), rand(200, 160), rand(200, 160)); //中间背景
$middleground2 = imagecolorallocatealpha($im, rand(180, 140), rand(180, 140), rand(180, 140),80); //中间背景2

//与左上角的颜色相同的都会被填充
imagefill($im, 0, 0, imagecolorallocate($im, 250, 253, 254));
//往图像上写入文字
imagettftext($im, 12, rand(30, -30), 5, rand(14, 16), $foregroundArr[rand(0,3)], XINCHENG_ROOT.'include/fonts/ALGER.TTF', $string[0]);
imagettftext($im, 12, rand(50, -50), 20, rand(14, 16), $foregroundArr[rand(0,3)], XINCHENG_ROOT.'include/fonts/ARIALNI.TTF', $string[1]);
imagettftext($im, 12, rand(50, -50), 35, rand(14, 16), $foregroundArr[rand(0,3)], XINCHENG_ROOT.'include/fonts/ALGER.TTF', $string[2]);
imagettftext($im, 12, rand(30, -30), 50, rand(14, 16), $foregroundArr[rand(0,3)], XINCHENG_ROOT.'include/fonts/arial.ttf', $string[3]);

//画边框
$border = imagecolorallocate($im, 133, 153, 193);
imagerectangle($im, 0, 0, $imageX - 1, $imageY - 1, $border);

//画一些随机出现的点
$pointcol = imagecolorallocate($im, rand(0,255), rand(0,255), rand(0,255));
for ($i=0;$i<80;$i++)
{
imagesetpixel($im,rand(2,$imageX-2),rand(2,$imageX-2),$pointcol);
}
//画随机出现的线
for ($x=0; $x<9;$x++)
{
if(mt_rand(0,$x)%2==0)
{
imageline($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 999999)); //画线
imageellipse($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $middleground2); //画椭圆
}
else
{
imageline($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 999999));
imageellipse($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $middleground);
}
}
//output to browser
header("content-type:image/png\r\n");
imagepng($im);
imagedestroy($im);
}
else
{
$files = glob(XINCHENG_ROOT.'images/checkcode/*.jpg');
if(!is_array($files)) die('请检查文件目录完整性:/images/checkcode/');

$checkcodefile = $files[rand(0, count($files)-1)]; //随机其中一个文件
$_SESSION['checkcode'] = substr(basename($checkcodefile), 0, 4); //获得文件名

header("content-type:image/jpeg\r\n");
include $checkcodefile;
}
?>

㈣ 求一个PHP格式的验证码代码~谢谢~

<?php
session_start();
function random($len)
{
if($i==0)
{
$str="";
$s="";
for($i=0;$i <$len;$i++){
$s.=$str[rand(0,35)];
}
}
return strtoupper($s);
}
$code=random(4); //随机生成的字符串
$width = 50; //验证码图片的宽度
$height = 20; //验证码图片的高度
@header("Content-Type:image/png");
$_SESSION["code"] = $code;
$im=imagecreate($width,$height);
//背景色
$back=imagecolorallocate($im,255, 255, 255);
//模糊点颜色
$pix=imagecolorallocate($im,187,230,247);
//字体色
$font=imagecolorallocate($im,41,163,238);
//绘模糊作用的点
for($i=0;$i <1000;$i++)
{
imagesetpixel($im,rand(0,$width),rand(0,$height),$pix);
}
imagestring($im, 5, 7, 2,$code, $font);
imagerectangle($im,0,0,$width-1,$height-1,$font);
imagepng($im);
imagedestroy($im);
?>
我一般都用这个的。解释什么都比较清楚。

㈤ php验证码怎么实现

1.新建code.php验证码生成文件

在此之前必须打开php的GD库,修改php.ini文件的配置,取消extension=php_gd2.dll前面的分号。代码如下:

<?php

session_start();

//生成验证码图片

Header("Content-type: image/PNG");

$im = imagecreate(44,18);

$back = ImageColorAllocate($im, 245,245,245);

imagefill($im,0,0,$back); //背景

srand((double)microtime()*1000000);

//生成4位数字

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

$font = ImageColorAllocate($im, rand(100,255),rand(0,100),rand(100,255));

$authnum=rand(1,9);

$vcodes.=$authnum;

imagestring($im, 5, 2+$i*10, 1, $authnum, $font);

}

for($i=0;$i<100;$i++) //加入干扰象素

{

$randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));

imagesetpixel($im, rand()p , rand()0 , $randcolor);

}

ImagePNG($im);

ImageDestroy($im);

$_SESSION['Checknum'] = $vcodes;

?>

2. 显示验证码图片

在需要显示验证码的页面中加入

<input type="text" name="passcode" >

<img src="code.php">

3.判断并获取验证码的值

验证码是通过第一步骤代码中的$_SESSION['Checknum'] = $vcodes;赋的值,所以验证码的值存在$_SESSION['Checknum']当中。在验证页面,使用以下代码,

...

session_start();//启动会话

$code=$_POST["passcode"];

if( $code == $_SESSION["Checknum"])

{...}即可完成验证码登录。

运行截图:

望采纳,谢谢

㈥ php实现验证码,能给具体的代码吗 在这谢谢过各位高手了

index.php:
<?php
/* index.php start*/
if(!empty($_POST)) {
session_start();
if($_POST['seccode'] == $_SESSION['seccode']) {
echo '<script>alert("验证成功")</script>';
} else {
echo '<script>alert("验证失败")</script>';
}
session_destroy();
}
?>
<form action="" method="post" />
<img id="seccode" src="seccode.php?rand=".<?=rand()?> /> <input type="text" name="seccode" /> <input type="submit" value="submit" />
<input type="button" onclick="document.getElementById('seccode').src = 'seccode.php?reload=1&' + Math.random()" value="change one"/>
</form>

<?php
/* index.php end*/
?>

******************************
seccode.php:
<?php
/*seccode.php start*/
session_start();
if(isset($_SESSION['seccode']) && empty($_GET['reload'])) {
$arr = $_SESSION['seccode'];
} else {
for($i=0; $i<4; $i++) {
$arr[] = rand(0, 9);
}
$_SESSION['seccode'] = implode($arr);
}
$im = imagecreate(90, 25);
$backgroundcolor = imagecolorallocate ($im, 255, 255, 255);

for($i = 0; $i < 4; $i++) {
$s = iconv('GBK', 'UTF-8', $arr[$i]);
$x = $i * 20 + mt_rand(0, 4) - 2;// 随机X
$y = mt_rand(0, 4); // 随机Y
$angle = mt_rand(0,4);// 随机角度
$text_color = imagecolorallocate($im, mt_rand(50, 255), mt_rand(50, 128), mt_rand(50, 255)); // 随机颜色
imagettftext($im,20, $angle,$x,20+$y,$text_color,"C:\\Windows\\Fonts\\SIMSUN.TTC",$s);
}

// 线条
$linenums = mt_rand(10, 32);
for($i=0; $i <= $linenums; $i++) {
$linecolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
$linex = mt_rand(0, 62);
$liney = mt_rand(0, 25);
imageline($im, $linex, $liney, $linex + mt_rand(0, 4) - 2, $liney + mt_rand(0, 4) - 2, $linecolor);
}

// 杂点
for($i=0; $i <= 64; $i++) {
$pointcolor = imagecolorallocate($im, mt_rand(50, 255), mt_rand(50, 255), mt_rand(50, 255));
imagesetpixel($im, mt_rand(0, 62), mt_rand(0, 25), $pointcolor);
}

// 边框
$bordercolor = imagecolorallocate($im , 150, 150, 150);
imagerectangle($im, 0, 0, 89, 24, $bordercolor);

header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
/*seccode.php end*/
?>

㈦ php登陆页面验证码验证代码怎么写

php登陆页面+验证码的实现,参考如下: 1、首先新建一个php站点; 2、先新建一个命名为yzm.php文件,双击编辑,清空Dreamweaver自动生成的HTML代码

㈧ PHP 绘制网站登录首页图片验证码

几乎所有的网站登录页都会有验证码,验证码是一种安全保护机制,在注册时要求必须有人工操作进行验证,用于防止垃圾注册机大量注册用户账号占用服务器内存从而使服务器瘫痪。
图片验证码的实现十分简单。首先从指定字符集合中随机抽取固定数目的字符,以一种不规则的方法画在画布上,再适当添加一些干扰点和干扰元素,最后将图片输出,一张崭新的验证码就完成了。
先给大家展示下生成的验证码:

点击刷新:

如果大家对实现效果非常满意,请继续往下看。
前端代码如下:
<!DOCTYPE
html>
<html>
<head>
<meta
http-equiv="content-type"
content="text/html;charset=utf-8">
<title>This
is
a
test!</title>
<link
rel="stylesheet"
type="text/css"
href="css/bootstrap.min.css">
</head>
<body>
<form
name="form">
<input
type="text"
placeholder="账号"/><br/>
<input
type="password"
placeholder="密码"/><br/>
<input
type="text"
placeholder="验证码"/>
<img
id="verImg"
src="libs/verification.php"/>
<a
href="#"
class="change"
onclick="changeVer()">点击刷新</a><br/>
<input
type="submit"
value="登录"/>
</form>
<script
type="text/javascript">
//刷新验证码
function
changeVer(){
document.getElementById("verImg").src="libs/verification.php?tmp="+Math.random();
}
</script>
</body>
</html>
php脚本文件验证码的代码如下:
<?php
session_start();
//开启session记录验证码数据
vCode(4,
15);//设置验证码的字符个数和图片基础宽度
//vCode
字符数目,字体大小,图片宽度、高度
function
vCode($num
=
4,
$size
=
20,
$width
=
0,
$height
=
0)
{
!$width
&&
$width
=
$num
*
$size
*
4
/
5
+
15;
!$height
&&
$height
=
$size
+
10;
//设置验证码字符集合
$str
=
"";
//保存获取的验证码
$code
=
''
//随机选取字符
for
($i
=
0;
$i
<
$num;
$i++)
{
$code
.=
$str[mt_rand(0,
strlen($str)-1)];
}
//创建验证码画布
$im
=
imagecreatetruecolor($width,
$height);
//背景色
$back_color
=
imagecolorallocate($im,
mt_rand(0,100),mt_rand(0,100),
mt_rand(0,100));
//文本色
$text_color
=
imagecolorallocate($im,
mt_rand(100,
255),
mt_rand(100,
255),
mt_rand(100,
255));
imagefilledrectangle($im,
0,
0,
$width,
$height,
$back_color);
//
画干扰线
for($i
=
0;$i
<
5;$i++)
{
$font_color
=
imagecolorallocate($im,
mt_rand(0,
255),
mt_rand(0,
255),
mt_rand(0,
255));
imagearc($im,
mt_rand(-
$width,
$width),
mt_rand(-
$height,
$height),
mt_rand(30,
$width
*
2),
mt_rand(20,
$height
*
2),
mt_rand(0,
360),
mt_rand(0,
360),
$font_color);
}
//
画干扰点
for($i
=
0;$i
<
50;$i++)
{
$font_color
=
imagecolorallocate($im,
mt_rand(0,
255),
mt_rand(0,
255),
mt_rand(0,
255));
imagesetpixel($im,
mt_rand(0,
$width),
mt_rand(0,
$height),
$font_color);
}
//随机旋转角度数组
$array=array(5,4,3,2,1,0,-1,-2,-3,-4,-5);
//
输出验证码
//
imagefttext(image,
size,
angle,
x,
y,
color,
fontfile,
text)
@imagefttext($im,
$size
,
array_rand($array),
12,
$size
+
6,
$text_color,
'c:WINDOWSFontssimsun.ttc',
$code);
$_SESSION["VerifyCode"]=$code;
//no-cache在每次请求时都会访问服务器
//max-age在请求1s后再次请求会再次访问服务器,must-revalidate则第一发送请求会访问服务器,之后不会再访问服务器
//
header("Cache-Control:
max-age=1,
s-maxage=1,
no-cache,
must-revalidate");
header("Cache-Control:
no-cache");
header("Content-type:
image/png;charset=gb2312");
//将图片转化为png格式
imagepng($im);
imagedestroy($im);
}
?>
好了,关于小编给大家介绍的php绘制图片验证就给大家介绍这么多,希望对大家有所帮助!

㈨ php验证码代码问题

把第一行的?换为:
<?php

不需要PNG文档。

㈩ 怎么用原生php做验证码

<?php
class validateCode{
private $charset=''; //随机因子
private $_len;
private $code; //验证码
private $codelen=4; //验证码长度
private $width=130; //画布宽度
private $height=50; //画布长度
private $img; //图形资源句柄
private $font; //制定字体
private $fontsize=26;//字体大小
private $fontcolor; //字体颜色

//初始化构造函数
public function __construct(){
$this->font=dirname(__file__).'/validateFont.ttf';
//字体文件及路径,__file__表示当前PHP文件绝对路径,dirname表示这个PHP文件的绝对路径的上一层
}

//生成随机码
private function createCode(){
$this->_len=strlen($this->charset)-1; //strlen表示计算字符串长度
for($i=1;$i<=$this->codelen;$i++){
$this->code.=$this->charset[mt_rand(0,$this->_len)];
}
}
//生成背景
private function createBG(){
$this->img=imagecreatetruecolor($this->width,$this->height);//创建图像
$color=imagecolorallocate($this->img,mt_rand(157,255),mt_rand(157,255),mt_rand(157,255)); //分配颜色函数(红,绿,蓝)
imagefilledrectangle($this->img,0,$this->height,$this->width,0,$color); //矩形区域着色函数(要填充的图像,x1,y1,x2,y2,要填充的颜色),x1,y1,x2,y2表示矩形的对角线
}

//生成文字
private function createFont(){
$_x=$this->width/$this->codelen;
for($i=0;$i<$this->codelen;$i++){
$this->fontcolor=imagecolorallocate($this->img,mt_rand(0,156),mt_rand(0,156),mt_rand(0,156));
imagettftext($this->img,$this->fontsize,mt_rand(-30,30),$_x*$i+mt_rand(1,5),$this->height/1.4,$this->fontcolor,$this->font,$this->code[$i]); //参数 size 为字形的尺寸;angle 为字型的角度,顺时针计算,0 度为水平,也就是三点钟的方向 (由左到右),90 度则为由下到上的文字;x,y 二参数为文字的坐标值 (原点为左上角);参数 col 为字的颜色;fontfile 为字型文件名称,亦可是远端的文件;text 当然就是字符串内容了。
}
}

//生成线条雪花
private function createLine(){
//线条
for($i=0;$i<6;$i++){
$color=imagecolorallocate($this->img,mt_rand(0,156),mt_rand(0,156),mt_rand(0,156));
imageline($this->img,mt_rand(0,$this->width),mt_rand(0,$this->height),mt_rand(0,$this->width),mt_rand(0,$this->height),$color);
}

//雪花
for($i=0;$i<40;$i++){
$color=imagecolorallocate($this->img,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255));
imagestring($this->img,mt_rand(1,5),mt_rand(0,$this->width),mt_rand(0,$this->height),'*',$color);
}
}

//输出
private function outPut(){
header("content-type:image/png");
imagepng($this->img);
imagedestroy($this->img);
}

//对外生成
public function doimg(){
$this->createCode();
$this->createBg();
$this->createFont();
$this->createLine();
$this->outPut();
}

//获取验证码
public function getCode(){
return strtolower($this->code);
}
}
?>
字体自己去找,修改下路径就行了

阅读全文

与php验证码源代码相关的资料

热点内容
8051单片机包含多大的ram 浏览:811
man文件linux 浏览:282
javaweb实现页面跳转 浏览:125
命令如什么 浏览:315
centos如何使用ftp服务器 浏览:981
直立车陀螺仪算法 浏览:69
coreldrawpdf下载 浏览:895
虚拟主机云服务器软件服务 浏览:370
苹果的怎么拉安卓的打游戏 浏览:412
游戏程序员负责角色 浏览:313
于丹pdf 浏览:717
反编译ref 浏览:550
鸿蒙智能文件夹怎么弄 浏览:547
grunt压缩html 浏览:791
macpdfword转换器 浏览:908
压缩面膜是什么材质 浏览:355
抖音发布作品怎么建文件夹 浏览:17
安卓如何更改谷歌地区 浏览:276
airpods为什么安卓连上声音很大 浏览:514
联想服务器按钮怎么开不了机 浏览:99