1. php验证码问题
把
<?php
有关生成验证码的代码
?>
换成<img
src="yzm.php">
即可
yzm.php 上面
session_start()
前面的注释也要去掉,而且里面很多变量没有定义,如果PHP.INI开了错误提示,就是出错,提示变量不存在,就不会显示验证码。
login.php里面,空格
符应该是
不是
nbps
我写好了,放在我网站上了,演示效果网址:
http://dev.qkweb.net/php/yzm/login.php
下载代码的地址是:
http://dev.qkweb.net/php/yzm/20110701yzm.rar
2. php验证码怎么使用
把以上代码保存成code.php,上传到相应目录,如网站根目录 调用的时候 <img src="code.php"> 即可
3. PHP 验证码怎样设置
补充:
验证码可以同cookie或者session的方式传递数据,
不用有特别的设置,不过要安装GD库,否则不能显示图片.
随便放在哪里都可以,
显示是以图片方式显示,
例如验证码的程序文件是ck.php
那么显示就是
<img src = "ck.php">
验证码有很多种编写方式,当然是众说纷纭,
凡是程序都不会有一个统一的格式,只有统一的思路.
4. 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);
?>
5. 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*/
?>
6. PHP curl模拟登陆阿里妈妈的代码怎么写,告急!
你用firebug看看要什么参数,然后再看看,有没有随机参数,远程提交表单!!验证码先获取cookies再请求就可以获取到配套的验证码
7. 如何用PHP生成验证码
PHP生成验证码的原理:使用PHP的GD库,生成一张带验证码的图片,并将验证码保存在Session中。PHP生成验证码的大致流程有:
1、产生一张png的图片;
2、为图片设置背景色;
3、设置字体颜色和样式;
4、产生4位数的随机的验证码;
5、把产生的每个字符调整旋转角度和位置画到png图片上;
6、加入噪点和干扰线防止注册机器分析原图片来恶意破解验证码;
7、输出图片;
8、释放图片所占内存。
session_start();
getCode(4,60,20);
functiongetCode($num,$w,$h){
$code="";
for($i=0;$i<$num;$i++){
$code.=rand(0,9);
}
//4位验证码也可以用rand(1000,9999)直接生成
//将生成的验证码写入session,备验证时用
$_SESSION["helloweba_num"]=$code;
//创建图片,定义颜色值
header("Content-type:image/PNG");
$im=imagecreate($w,$h);
$black=imagecolorallocate($im,0,0,0);
$gray=imagecolorallocate($im,200,200,200);
$bgcolor=imagecolorallocate($im,255,255,255);
//填充背景
imagefill($im,0,0,$gray);
//画边框
imagerectangle($im,0,0,$w-1,$h-1,$black);
//随机绘制两条虚线,起干扰作用
$style=array($black,$black,$black,$black,$black,
$gray,$gray,$gray,$gray,$gray
);
imagesetstyle($im,$style);
$y1=rand(0,$h);
$y2=rand(0,$h);
$y3=rand(0,$h);
$y4=rand(0,$h);
imageline($im,0,$y1,$w,$y3,IMG_COLOR_STYLED);
imageline($im,0,$y2,$w,$y4,IMG_COLOR_STYLED);
//在画布上随机生成大量黑点,起干扰作用;
for($i=0;$i<80;$i++){
imagesetpixel($im,rand(0,$w),rand(0,$h),$black);
}
//将数字随机显示在画布上,字符的水平间距和位置都按一定波动范围随机生成
$strx=rand(3,8);
for($i=0;$i<$num;$i++){
$strpos=rand(1,6);
imagestring($im,5,$strx,$strpos,substr($code,$i,1),$black);
$strx+=rand(8,12);
}
imagepng($im);//输出图片
imagedestroy($im);//释放图片所占内存
}
8. 怎样用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);
}
}