导航:首页 > 编程语言 > php算术验证码

php算术验证码

发布时间:2022-06-23 10:52:07

1. php 怎么获取验证码的值

$_SESSION["vcode"] = $vcode;
验证码的值就在 $_SESSION["vcode"] 里面。

2. 求大神:网页验证码问题,JS或PHP人士请看:如何让验证码错误提示后用户名和密码记录仍在

把<div...>后台管理</div>标签下面的js脚本换成我下面改的那样,同时把表单里的onsubmit="return Checklogin();" 这个属性删掉,试试看:
<script>
$(function(){
//算术验证
$("#getcode_math").click(function(){
$(this).attr("src",'code_math.php?' + Math.random());
});

$("#chk_math").click(function(){
if (loginform.user.value=="") { //有个疑问,loginform.user.value能拿到输入的用户名吗?
alert("请填写登录名");
loginform.user.focus();
return false;
}
if (loginform.pw.value=="") { //还有这样,能拿到输入的密码?
alert("密码不能为空");
loginform.pw.focus();
return false;
}

var code_math = $("#code_math").val();
var XMLHttpRequest = $.post("chk_code.php?act=math",{code:code_math},function(msg){
if(msg==0){
alert("验证码错误!");
}
});
if (XMLHttpRequest.responseText == 0) {
return false;
}
});
});
</script>

3. 请教网页制作中PHP验证码实现问题。

在文件1用表单提交给文件2,输入验证码肯定是在表单的输入框里,输入好后提交表单时对象是文件2就行了。注意php需要服务器支持啊,没服务器直接当文本打开了。

4. 怎么用原生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);
}
}
?>
字体自己去找,修改下路径就行了

5. php验证码怎么使用

调用你这个代码里已经生成的验证码,我给你的是用户输入时候的页面,你还要再写一个验证的页,就是验证用户输入的和代码生成的是否一样 <form action="**.php" method="post"> <table> <tr> <td width="490" align="left"> <input size="8" name="$vcode" /> <img src="./verifyImg.php"(比如说这个是你的文件的文件名) onClick="this.src='./verifyImg.php?=random'+Math.random();" style="cursor:pointer;"> <span>点击切换图片</span><br /> <input type="submit" value="提交" /> </td></tr></table>

6. php验证码判断

session_start();
$str_number = trim($_POST['number']);
if(strtolower($_SESSION['rand'])==strtolower($str_number )){
echo "验证码正确";
}else{
echo "验证码不正确";
}

最好加strtolower函数转换下大小写,这样子,用户在输入时就不用区分大小写了。不然用户体验会很麻烦,这是我个人理解。

7. 怎样用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);
}
}

8. PHP验证码代码问题

<form action="" method="post">

<img src='2.php'><br> “ 这句调用的文件对不,是你第一个文件不?你把这个 2.php换成你验证码的那个文件试试

<input type="text" name="check" ><br>
<input type="submit" value="提交" ><br>

</form>

9. PHP如何生成加减算法方式的验证码

<?php
namespace mobile\components;
/**
* @author fenghuo
*
* 改造的加减法验证类
* 使用示例 VerifyCode::get(1,2);
* 验证示例 VerifyCode::check($code);
*/
class VerifyCode
{
/**
* php验证码
*/
public static function get($one,$two,$prefix = '', $font_size = 28)
{
//文件头...
ob_get_clean();
header("Content-type: image/png;charset=utf-8;");
//创建真彩色白纸
$width = $font_size*5;
$height = $font_size+1;
$im = @imagecreatetruecolor($width, $height) or die("建立图像失败");
//获取背景颜色
$background_color = imagecolorallocate($im, 255, 255, 255);
//填充背景颜色
imagefill($im, 0, 0, $background_color);
//获取边框颜色
$border_color = imagecolorallocate($im, 200, 200, 200);
//画矩形,边框颜色200,200,200
imagerectangle($im,0,0,$width - 1, $height - 1,$border_color);
//逐行炫耀背景,全屏用1或0
for($i = 2;$i < $height - 2;$i++) {
//获取随机淡色
$line_color = imagecolorallocate($im, rand(200,255), rand(200,255), rand(200,255));
//画线
imageline($im, 2, $i, $width - 1, $i, $line_color);
}
//设置印上去的文字
$firstNum = $one;
$secondNum = $two;
$actionStr = $firstNum > $secondNum ? '-' : '+';
//获取第1个随机文字
$imstr[0]["s"] = $firstNum;
$imstr[0]["x"] = rand(2, 5);
$imstr[0]["y"] = rand(1, 4);
//获取第2个随机文字
$imstr[1]["s"] = $actionStr;
$imstr[1]["x"] = $imstr[0]["x"] + $font_size - 1 + rand(0, 1);
$imstr[1]["y"] = rand(1,5);
//获取第3个随机文字
$imstr[2]["s"] = $secondNum;
$imstr[2]["x"] = $imstr[1]["x"] + $font_size - 1 + rand(0, 1);
$imstr[2]["y"] = rand(1, 5);
//获取第3个随机文字
$imstr[3]["s"] = '=';
$imstr[3]["x"] = $imstr[2]["x"] + $font_size - 1 + rand(0, 1);
$imstr[3]["y"] = 3;
//获取第3个随机文字
$imstr[4]["s"] = '?';
$imstr[4]["x"] = $imstr[3]["x"] + $font_size - 1 + rand(0, 1);
$imstr[4]["y"] = 3;
//文字
$text = '';
//写入随机字串
for($i = 0; $i < 5; $i++) {
//获取随机较深颜色
$text_color = imagecolorallocate($im, rand(50, 180), rand(50, 180), rand(50, 180));
$text .= $imstr[$i]["s"];
//画文字
imagechar($im, $font_size, $imstr[$i]["x"], $imstr[$i]["y"], $imstr[$i]["s"], $text_color);
}
session_start();
$_SESSION[$prefix.'verifycode'] = $firstNum > $secondNum ? ($firstNum - $secondNum) : ($firstNum + $secondNum);
//显示图片
ImagePng($im);
//销毁图片
ImageDestroy($im);
}
public static function check($code)
{
if(trim($_SESSION[$prefix.'verifycode']) == trim($code)) {
return true;
} else {
return false;
}
}

10. php 怎么获取验证码的值,接着怎么写

验证码一般都保存在session中,打印一下session的值,就能看到验证码对应的字段、值;
mp($_SESSION);

阅读全文

与php算术验证码相关的资料

热点内容
程序员如何不被废 浏览:803
二进制流转pdf 浏览:915
php判断爬虫 浏览:569
960除24除4简便算法 浏览:786
关于解压英语翻译 浏览:565
python控制键盘右键 浏览:920
php没有libmysqldll 浏览:828
时政新闻app哪个好 浏览:906
手机已加密怎么办 浏览:201
安卓手机截屏怎么传到苹果 浏览:527
京管家app哪里下载 浏览:33
文件夹横向排列的竖向排列 浏览:453
51单片机驱动摄像头模块 浏览:689
政府文件加密没法转换 浏览:373
android判断栈顶 浏览:331
凭证软件源码 浏览:860
androidwebview滚动事件 浏览:11
如何将电脑上的图片压缩成文件包 浏览:899
程序员转金融IT 浏览:837
黑马程序员培训效果如何 浏览:915