php验证码下载
❶ 如何制作php验证码
从头开始讲验证码制作不太现实 不是简单几句话就能讲完 建议你网络找下 “验证码类” 下载使用 也可以看他的代码学习制作
❷ 我的php代码中登陆界面加一个验证码,如何实现
php登陆页面+验证码的实现,参考如下:
1、首先新建一个php站点;
❸ 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;
}
?>
❹ 如何解决thinkphp5中验证码常见问题
第一个问题就是:
提示Call to undefined function captcha_src()。这是因为我们的扩展目录不存在验证文件。我们采用comoser进行安装(这里就介绍这一种了)或者采用直接到官网下载完版本的。
在我们的vendor目录下运行如下命令。
composer require topthink/think-captcha
接下来,我们的目录下会出现如下目录。
第二个问题:如果图片路径错误问题,按照如下图片所示添加内容。
第三个问题:配置项配置不正确。找到我们的config.php文件添加将下面的参数值设置为true。
'url_route_on' => true,
好了,设计到的问题已经介绍完了,不知道为你解决没?如果没欢迎骚扰。
❺ 我下了一个php格式的验证码文件如何用到html中
验证码:
<input name="validcode" id="validcode" size="6" maxlength="4"> <img name="validate" onclick="validate.src+='?' + Math.random();" src="Inc/code.php"> <a href="#" onclick="javascript:validate.src+='?' + Math.random();return false;" >看不清?点击刷新</a>
//注:src="Inc/code.php" 是对应路径
❻ 如何用PHP生成验证码
php生成验证码,php验证码,php怎样生成验证码?
工具/原料
这个验证码较实用,大家可以应用到项目中。
方法/步骤
1.
<?php
/*设置文件头为图片输出*/
Header("Content-type:image/JPEG");
/*调用生成验证码函数*/
$checkcode=make_rand(4);
/**
*生成验证码字符
*@paramint$length验证码字符长度
*@returnstring
*/
functionmake_rand($length="32"){
$str="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$result="";
for($i=0;$i<$length;$i++){
$num[$i]=rand(0,25);
$result.=$str[$num[$i]];
}
return$result;
}
2.
/*调用输出验证码图片函数*/
getAuthImage($checkcode,160,40);
/**
*生成验证码图片
*@paramstring$text验证码字符
*/
functiongetAuthImage($text,$w,$y){
/*设置图片的宽度和高度*/
$im_x=$w;
$im_y=$y;
/*创建图片*/
$im=imagecreatetruecolor($im_x,$im_y);
$text_c=ImageColorAllocate($im,mt_rand(0,100),mt_rand(0,100),mt_rand(0,100));
$tmpC0=mt_rand(100,255);
$tmpC1=mt_rand(100,255);
$tmpC2=mt_rand(100,255);
$buttum_c=ImageColorAllocate($im,$tmpC0,$tmpC1,$tmpC2);
imagefill($im,16,13,$buttum_c);
3.
/*字体文件*/
$font='t1.ttf';
for($i=0;$i<strlen($text);$i++)
{
$tmp=substr($text,$i,1);
$array=array(-1,1);
$p=array_rand($array);
$an=$array[$p]*mt_rand(1,10);//角度
$size=28;
imagettftext($im,$size,$an,15+$i*$size,35,$text_c,$font,$tmp);
}
/*将字符写入文件中*/
$distortion_im=imagecreatetruecolor($im_x,$im_y);
imagefill($distortion_im,16,13,$buttum_c);
for($i=0;$i<$im_x;$i++){
for($j=0;$j<$im_y;$j++){
$rgb=imagecolorat($im,$i,$j);
if((int)($i+20+sin($j/$im_y*2*M_PI)*10)<=imagesx($distortion_im)&&(int)($i+20+sin($j/$im_y*2*M_PI)*10)>=0){
imagesetpixel($distortion_im,(int)($i+10+sin($j/$im_y*2*M_PI-M_PI*0.1)*4),$j,$rgb);
}
}
}
4.
/*干扰元素点的数量*/
$count=160;
/*创建干扰元素点*/
for($i=0;$i<$count;$i++){
$randcolor=ImageColorallocate($distortion_im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
imagesetpixel($distortion_im,mt_rand()%$im_x,mt_rand()%$im_y,$randcolor);
}
/*创建干扰线条*/
$rand=mt_rand(5,30);
$rand1=mt_rand(15,25);
$rand2=mt_rand(5,10);
for($yy=$rand;$yy<=+$rand+2;$yy++){
for($px=-80;$px<=80;$px=$px+0.1)
{
$x=$px/$rand1;
if($x!=0)
{
$y=sin($x);
}
$py=$y*$rand2;
imagesetpixel($distortion_im,$px+80,$py+$yy,$text_c);
}
}
5.
/*以PNG格式将图像输出到浏览器*/
ImagePNG($distortion_im);
/*销毁图像*/
ImageDestroy($distortion_im);
ImageDestroy($im);
❼ php验证码字体的问题
//设置字体样式
$font=dirname(__FILE__).'/font/arial.ttf';
$font在提供的代码里其实没有用到,而它正是用来指定字体的。
.ttf文件是一个字体库,这种文件在系统中其实很多,你可以在C盘搜索一下.ttf,也可以到网上去下载喜欢的。
然后将$font赋值为.ttf文件所在的路径,或者将.ttf文件复制到$font设置的路径。
//输出验证码
for($i=0;$i<strlen($_SESSION['code']);$i++){
imagestring($_img,$font_size,$i*$_width/$codelen+mt_rand(1,10),mt_rand(1,$_height/2),$_SESSION['code'][$i],$font_color);
}
这段是画验证码的代码,但是imagestring方法不提供字体设置,要换成imagettftext方法。
修改如下
for($i=0;$i<strlen($_SESSION['code']);$i++){
imagettftext($_img,$font_size,0,$i*$_width/$codelen+mt_rand(1,10),mt_rand(1,$_height/2),$font_color,$font,$_SESSION['code'][$i]);
}
❽ PHP验证码显示问题 GD库函数imagecreatetruecolor使用不了 求救
Call
to
undefined
function
imagecreatetruecolor()
in
...
提示是:调用未定义的函数imagecreatetruecolor
你的
gd库
文件没有打开。
先打开你的php.
ini文件
查找
;extension=php_gd2.dll
,把前面的分号去掉,如果没有这句就加个(当然不要带分号,分号是注释掉的意思)然后保存退出。
如果没有gd2.
dll文件
的话,就到网上下载一个
重新启动apache服务器。
❾ 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*/
?>