导航:首页 > 编程语言 > php中文验证码类

php中文验证码类

发布时间:2022-05-26 02:52:45

1. php验证码类帮看下,谢谢很短

一、修改php.ini(保举)

memory_limit = 12M

2、在程序里面添加如下语句

ini_set(''memory_limit'', ''12M'');

3、在根目录建立

.htaccess文件,添加如下内容

php_value memory_limit 12M

如果还不能解决,就把它改得再大一些。

最后注意的是重启服务器
==========================
上面是我抄的,看到你的提问我感觉是配置的问题,但我这人记不住东西,只能找,其实你把报错的提示一搜就会有答案的

2. 请问PHP生成验证码的类怎么写

<?php
classCode{
//1.定义各个成员有宽、高、画布、字数、类型、画类型
private$width;//宽度
private$height;//高度
private$num;//验证码字数
private$imgType;//生成图片类型
private$Type;//字串类型1,2,3三个选项1纯数字2纯小写字母3大小写数字混合
private$hb;//画布
public$codestr;//验证码字串
publicfunction__construct($height=20,$num=4,$imgType="jpeg",$Type=1){
$this->width=$num*20;
$this->height=$height;
$this->num=$num;
$this->imgType=$imgType;
$this->Type=$Type;
$this->codestr=$this->codestr();
$this->zuhe();
}
//2.定义随机获取字符串函数
privatefunctioncodestr(){
switch($this->Type){
case1://类型为1获取1-9随机数
$str=implode("",array_rand(range(0,9),$this->num));
break;
case2://类型为2获取a-z随机小写字母
$str=implode("",array_rand(array_flip(range(a,z)),$this->num));
break;
case3://类型为3获取数字,小写字母,大写字母混合
for($i=0;$i<$this->num;$i++){
$m=rand(0,2);
switch($m){
case0:
$o=rand(48,57);
break;
case1:
$o=rand(65,90);
break;
case2:
$o=rand(97,122);
break;
}
$str.=sprintf("%c",$o);
}
break;
}

return$str;
}

//3.初始化画布图像资源
privatefunctionHb(){
$this->hb=imagecreatetruecolor($this->width,$this->height);
}
//4.生成背景颜色
privatefunctionBg(){
returnimagecolorallocate($this->hb,rand(130,250),rand(130,250),rand(130,250));
}
//5.生成字体颜色
privatefunctionFont(){
returnimagecolorallocate($this->hb,rand(0,100),rand(0,100),rand(0,100));
}
//6.填充背景颜色
privatefunctionBgColor(){
imagefilledrectangle($this->hb,0,0,$this->width,$this->height,$this->Bg());
}
//7.干扰点
privatefunctionganrao(){
$sum=floor(($this->width)*($this->height)/3);
for($i=0;$i<$sum;$i++){
imagesetpixel($this->hb,rand(0,$this->width),rand(0,$this->height),$this->Bg());
}
}
//8.随机直线弧线
privatefunctionhuxian(){
for($i=0;$i<$this->num;$i++){
imageArc($this->hb,rand(0,$this->width),rand(0,$this->height),rand(0,$this->width),rand(0,$this->height),rand(0,360),rand(0,360),$this->Bg());
}
}
//9.写字
privatefunctionxiezi(){
for($i=0;$i<$this->num;$i++){
$x=ceil($this->width/$this->num)*$i;
$y=rand(1,$this->height-15);
imagechar($this->hb,5,$x+4,$y,$this->codestr[$i],$this->Font());
}
}
//10.输出
privatefunctionOutImg(){
$shuchu="image".$this->imgType;
$header="Content-type:image/".$this->imgType;
if(function_exists($shuchu)){
header($header);
$shuchu($this->hb);
}else{
exit("GD库没有此类图像");
}
}
//11.拼装
privatefunctionzuhe(){
$this->Hb();
$this->BgColor();
$this->ganrao();
$this->huxian();
$this->xiezi();
$this->OutImg();
}
publicfunctiongetCodeStr(){
return$this->codestr;
}
}

$a=newCode();
$a->getCodeStr();
?>

3. php中文验证码的思路是怎样的是在字符串里输入很多个中文让随机还是怎么样

$keyword = $_GET ['q']; //获取的q值是 "请选择" $choose="请选择"; if($keyword==$choose) echo "ok"; echo var_mp($keyword).var_mp($choose); //echo 的结果 $keyword=>string(9) "请选择" $choose=

4. 怎样用PHP制作验证码

<?php

//验证码类
classValidateCode{
private$charset='';//随机因子
private$code;//验证码
private$codelen=4;//验证码长度
private$width=90;//宽度
private$height=40;//高度
private$img;//图形资源句柄
private$font;//指定的字体
private$fontsize=20;//指定字体大小
private$fontcolor;//指定字体颜色
//构造方法初始化
publicfunction__construct(){
$this->font=dirname(__FILE__).'/font/elephant.ttf';//注意字体路径要写对,否则显示不了图片
}
//生成随机码
privatefunctioncreateCode(){
$_len=strlen($this->charset)-1;
for($i=0;$i<$this->codelen;$i++){
$this->code.=$this->charset[mt_rand(0,$_len)];
}
}
//生成背景
privatefunctioncreateBg(){
$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);
}
//生成文字
privatefunctioncreateFont(){
$_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]);
}
}
//生成线条、雪花
privatefunctioncreateLine(){
//线条
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<100;$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);
}
}
//输出
privatefunctionoutPut(){
header('Content-type:image/png');
imagepng($this->img);
imagedestroy($this->img);
}
//对外生成
publicfunctiondoimg(){
$this->createBg();
$this->createCode();
$this->createLine();
$this->createFont();
$this->outPut();
}
//获取验证码
publicfunctiongetCode(){
returnstrtolower($this->code);
}
}

5. php的验证码提示怎样制作

一般制作验证码会按照下面的几步走:
一:创建出来一个图片,通常我们成为源,可以用imagecreatetruecolor()这个函数搞定
二:给这个源 添加背景色,同时设置文本显示的颜色,GD库函数为我们提供了imagecolorallocate()函数
三:材料弄好了,我们要给它添点内容了,就是我们随机生成的数字或者字母,甚至可以是它们的组合,这里我们可以选择两个函数 imagettftext()、imagesrting(),这两个函数的不同,我们会在后面讲解。
例:
<?php
session_start();//开启session,用来记录获得的验证码,这个函数要写在程序的开头,不然会出现错误
header(“Content-type :image/gif”);//把文件的返回类型设为image/gif格式,这个格式可以输出图片
$codelen=4;//设置你要让用户输入字符的个数,一般为4,过长用户体验不好。
$charset =”ABCDEFGHKLMNPRSTUVWYZ23456789″;//我们可以尽量把一些难以辨认的字符去掉,比如阿拉伯数字0和字母o,这也是提高用户体验的一种方法。
$code =”;
for($i=0;$i<$codelen;$i++){//用for循环得到4个随机的字符,在这里用到了mt_rand,这个函数比rand的效率要高的多,建议大家用这个
$code .=$charset{mt_rand(0,strlen($charset)-1)};
}
$_SESSION['code']=$code;//下篇关于session验证的文章将会用到
$width = 80;
$height = 40;
$im = imagecreatetruecolor($width,$height);//用imagecreatetruecolor()函数来建立一个新的图片,里面的两个数值分别是宽度和高度,这是制作验证码的第一步
$bg = imagecolorallocate($im,255,255,0); //图片背景的颜色,这里是第二步
$textcolor = imagecolorallocate($im,255,0,0);//文字的颜色
imagefill($im,0,0,$bg);//给图片填充背景色
//好了上面的铺垫任务做的差不多了,现在关键就是让字符显示在图片上,这里有两种方法我们一一介绍。
$font =”ggbi.ttf”;//如果你有字体的话 就填上字体的相对路径,如果没有就留空。下面的两个用法我会一一讲解。
if($font!==”"){
for($num=0;$num<4;$num++){
imagettftext($im,mt_rand(12,16),(mt_rand(0,75)+330)%360,5+15*$num,20+mt_rand(2,5),$textcolor,$font,$code[$num]);//这里是第三步
}
}
else{
for($num=0;$num<4;$num++){
imagestring($im,5,10+15*$num,10+mt_rand(0,5),$code[$num],$textcolor);
}
}
header(“Content-type: image/jpeg”);
imagejpeg($im);
?>

6. thinkphp的验证码类库,如果需要使用中文验证码,那么需要将系统字体文件复制到

我的项目代码:

<?php
publicfunctionverify_code(){
$verify=newThinkVerify();

$verify->__set('seKey',C('VERIFY_KEY'));
$verify->__set('useZh',true);
$verify->__set('bg',array(235,246,230));
$verify->__set('length',2);
$verify->__set('fontSize',14);
$verify->__set('imageH',40);
$verify->__set('imageW',70);
$verify->__set('code',get_word());
return$verify->entry(1);
}
?>

get_word方法是随机获取一个两个字的词。

另外,字体是TP自带的。

目录在:/ThinkPHP/Library/Think/Verify/

7. php 中文 验证码 乱码、、、

楼主 我怀疑是编码问题 请查看个页面是否一致 都是UTF-8比如

8. PHP图片中文验证码生成问题

重新写了一下,这里不能print那个字符串..不然会出错
因为启动了session 之前不能有输出
最终$_SESSION['yzm']就是图片上的验证码..
--------------------
<?php
session_start();
$im = imagecreatetruecolor(80,30);
$bg = imagecolorallocate($im,0,0,0);
$te = imagecolorallocate($im,255,255,255);
for($i=0;$i<5;$i++)
{
$te2 = imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imageline($im,rand(0,80),0,80,rand(0,30),$te2);
}
for($i=0;$i<200;$i++)
{
imagesetpixel($im,rand()%100,rand()%30,$te2);
}
srand((float) microtime() * 10000000);
$input = array("步","步","高","请","转","到","图","像","我","非","常","高","兴");
$rand_keys = array_rand($input, 4);
$_SESSION['yzm'] = $t = $input[$rand_keys[0]].$input[$rand_keys[1]].$input[$rand_keys[2]].$input[$rand_keys[3]];
imagettftext($im,12,0,10,20,$te,'stxingka.ttf',$t);
header("content-type: image/jpeg");
imagejpeg($im);
?>

9. php中文验证码无法显示

session_start();
$image=imagecreatetruecolor(200,60);//创建画布
$color=imagecolorallocate($image,mt_rand(157,255),mt_rand(157,255),mt_rand(157,255));//随机颜色
//$color=imagecolorallocate($image,255,255,255);
imagefill($image,0,0,$color);//填充颜色
//中文验证码
$fontface="simhei.ttf";//确保相同目录下有该字体
$strdb=array('好','多','人','在','学','习');
for($i=0;$i<4;$i++){
$fontsizecolor=imagecolorallocate($image,mt_rand(0,150),mt_rand(0,150),mt_rand(0,150));
$codex=iconv("GB2312","UTF-8",$strdb[mt_rand(0,5)]);//iconv不能转数组取任意下标
imagettftext($image,mt_rand(20,24),mt_rand(-30,30),(40*$i+20),mt_rand(30,35),$fontsizecolor,$fontface,$codex);//如果用$code的话就生成1+2+3+4是个汉字的验证码了

}

//干扰点
for($i=0;$i<200;$i++){
$pointcolor=imagecolorallocate($image,mt_rand(50,200),mt_rand(50,200),mt_rand(50,200));
imagesetpixel($image,mt_rand(1,100),mt_rand(1,20),$pointcolor); //雪花
}
//干扰线
for($i=0;$i<3;$i++){
$linecolor=imagecolorallocate($image,mt_rand(50,200),mt_rand(50,200),mt_rand(50,200));
imageline($image,mt_rand(1,99),mt_rand(1,99),mt_rand(1,99),mt_rand(1,99),$linecolor);
}
ob_clean();
header("Content-type:image/png");
imagepng($image);
imagedestroy($image);

10. php 验证码类,怎么改变验证码形状

直接上代码:
复制代码 代码如下:
//验证码类
class ValidateCode {
private $charset = '';//随机因子private $code;//验证码
private $codelen = 4;//验证码长度
private $width = 130;//宽度
private $height = 50;//高度
private $img;//图形资源句柄
private $font;//指定的字体
private $fontsize = 20;//指定字体大小
private $fontcolor;//指定字体颜色
//构造方法初始化
public function __construct() {
$this->font = dirname(__FILE__).'/font/elephant.ttf';//注意字体路径要写对,否则显示不了图片}
//生成随机码
private function createCode() {
$_len = strlen($this->charset)-1;
for ($i=0;$i<$this->codelen;$i++) {
$this->code .= $this->charset[mt_rand(0,$_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);}
//生成文字
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]);}
}
//生成线条、雪花
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<100;$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->createBg();
$this->createCode();
$this->createLine();
$this->createFont();
$this->outPut();
}
//获取验证码
public function getCode() {
return strtolower($this->code);
}
}
输出实例:
使用方法:
1、先把验证码类保存为一个名为 ValidateCode.class.php 的文件;2、新建一个名为 captcha.php 的文件进行调用该类;captcha.php
复制代码 代码如下:
session_start();
require './ValidateCode.class.php'; //先把类包含进来,实际路径根据实际情况进行修改。
$_vc = new ValidateCode(); //实例化一个对象$_vc->doimg();
$_SESSION['authnum_session'] = $_vc->getCode();//验证码保存到SESSION中3、引用到页面中,代码如下:
复制代码 代码如下:
<img title="点击刷新" src="./captcha.php" align="absbottom" onclick="this.src='captcha.php?'+Math.random();"></img>
4、一个完整的验证页面,代码如下:
复制代码 代码如下:
<?php
session_start();
//在页首先要开启session,
//error_reporting(2047);
session_destroy();
//将session去掉,以每次都能取新的session值;//用seesion 效果不错,也很方便
?>
<html>
<head>
<title>session 图片验证实例</title>
<style type="text/css">
#login p{
margin-top: 15px;
line-height: 20px;
font-size: 14px;
font-weight: bold;
}
#login img{
cursor:pointer;
}
form{
margin-left:20px;
}
</style>
</head>
<body>
<form id="login" action="" method="post">
<p>此例为session验证实例</p>
<p>
<span>验证码:</span>
<input type="text" name="validate" value="" size=10>
<img title="点击刷新" src="./captcha.php" align="absbottom" onclick="this.src='captcha.php?'+Math.random();"></img>
</p>
<p>
<input type="submit">
</p>
</form>
<?php
//打印上一个session;
//echo "上一个session:<b>".$_SESSION["authnum_session"]."</b><br>";$validate="";
if(isset($_POST["validate"])){
$validate=$_POST["validate"];
echo "您刚才输入的是:".$_POST["validate"]."<br>状态:";if($validate!=$_SESSION["authnum_session"]){//判断session值与用户输入的验证码是否一致;echo "<font color=red>输入有误</font>";
}else{
echo "<font color=green>通过验证</font>";}
}
?>

阅读全文

与php中文验证码类相关的资料

热点内容
南京中兴招收专科程序员吗 浏览:297
代理商php源码 浏览:983
苹果手机怎么解压软件app 浏览:650
游戏资源被编译 浏览:152
代码编译后黑屏 浏览:8
程序员情侣写真 浏览:505
python3孪生素数 浏览:36
计算杨辉三角Python 浏览:404
linux目录重命名 浏览:196
算法设计的最终形态是代码 浏览:262
程序员社团招新横幅 浏览:238
拖鞋解压视频大全 浏览:887
租服务器主机链接软件叫什么 浏览:856
交叉编译工具的linux版本号 浏览:156
python开发应用软件 浏览:32
hdl综合器与c编译器的区别 浏览:899
编译原理最左推导代码 浏览:702
加密三 浏览:131
通过编译链接后形成的可执行程序 浏览:680
怎么用matlab编程 浏览:782