喜悦国际村 
» 游客:  注册 | 登录 | 搜索 | 统计 | 喜悦证交所 | 帮助

RSS 订阅当前论坛  

$5.95 Web Hosting     

上一主题 下一主题
     
标题: 分享,运用验证码的具体过程  
本帖已经被作者加入个人空间
 
c1a1o1
版主
Rank: 7Rank: 7Rank: 7
一品带刀护卫


UID 68669
精华 0
积分 1254
帖子 2220
金钱 1254 喜悦币
威望 0
人脉 0
阅读权限 100
注册 2006-2-17
状态 离线
[广告]: Enom域名自助付费 自助注册 自助PUSH 主流域名COM等一律57.99元年
分享,运用验证码的具体过程

以下:
index.php

<?php
 
<html>
<
head>
</
head>
<
body>
<
FORM name="form1" action="save.php" method="post">
  
<
TABLE cellSpacing=0 borderColorDark=#ffffff cellPadding=2 width="100%" align=center borderColorLight=#cccccc border=1>
        
        
<TR vAlign=center align=middle>
          <
TD width="70%" height=20><input type="text" name="testyan" value=""></TD>
          <
TD width="30%" ><img src="testyan.php?" align=absmiddle></TD></TR>
</
TABLE>
    <
center><input type="submit" name="s_snatch" value="提交"></center>
    </
body>
    </
html>
?>
注意以上代码!
testyan.php:

<?
  
function creatvalidateimg ($width$height$space$size$disturb_num$sname '')
  {
    
$left 1;
    
$top 0;
    
$authstr mt_rand (10009999);
    if ((
$sname != ''))
    {
      
$_SESSION[$sname] = $authstr;
    }

    
$image imagecreate ($width$height);
    
$colorList[] = imagecolorallocate ($image1573210);
    
$colorList[] = imagecolorallocate ($image461757);
    
$colorList[] = imagecolorallocate ($image2311853);
    
$colorList[] = imagecolorallocate ($image230164);
    
$colorList[] = imagecolorallocate ($image1998835);
    
$colorList[] = imagecolorallocate ($image17311461);
    
$colorList[] = imagecolorallocate ($image55179179);
    
$colorList[] = imagecolorallocate ($image17150153);
    
$colorList[] = imagecolorallocate ($image25452138);
    
$colorList[] = imagecolorallocate ($image00145);
    
$colorList[] = imagecolorallocate ($image00113);
    
$colorList[] = imagecolorallocate ($image228118237);
    
$colorList[] = imagecolorallocate ($image15818035);
    
$colorList[] = imagecolorallocate ($image2553636);
    
$colorList[] = imagecolorallocate ($image2557272);
    
$colorList[] = imagecolorallocate ($image24717951);
    
$gray imagecolorallocate ($image230230230);
    
imagefill ($image00$gray);
    for (
$i 0; ($i strlen ($authstr)); ++$i)
    {
      
$colorRandom mt_rand (0, (sizeof ($colorList) - 1));
      
imagestring ($image$size, (($space $i) + $left), $topsubstr ($authstr$i1), $colorList[$colorRandom]);
    }

    for (
$i 0; ($i $disturb_num); ++$i)
    {
      
$colorRandom mt_rand (0, (sizeof ($colorList) - 1));
      
imagesetpixel ($image, (rand () % 70), (rand () % 10), $colorList[$colorRandom]);
    }

    
header ('Content-type: image/PNG');
    
imagepng ($image);
    
imagedestroy ($image);
  }

  
session_start ();
  
//$_SESSION['sessionValid'] = mt_rand (1000, 9999);
 
  
creatvalidateimg (481810630'ValidateCode');
?> 
声明以上引用了本村的一个朋友的函数!
以下是save.php

<?
session_start 
();
echo  
$testyan;
$testyan=$_POST["testyan"];
$sessionValid=$_SESSION[ValidateCode];
if(
$testyan!=$sessionValid)
{
echo 
"post[testyan]=".$testyan."n";
echo 
"SESSION[$sname]=".$sessionValid."n";
echo 
"no good";
}
else
{
echo 
"post[testyan]=".$testyan."n";
echo 
"SESSION[$sname]=".$sessionValid."n";
echo 
"good!";
}
//$_SESSION = array();
// Finally, destroy the session.
//session_destroy();
echo "<meta http-equiv=\"Refresh\" content=\"5; url=index.php\">";
?> 




编程教材专卖
大学生兼职
2006-8-8 09:17 PM#1
查看资料  Blog  发短消息  QQ  顶部
     


  可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题 | 开通个人空间  


 




Powered by Discuz! 6.1.0  © 2001-2010 Comsenz Inc.
Processed in 3.396000 second(s), 6 queries

(冀ICP备05009913号) 管理员:sadly 邮箱/MSN: sadly@phpx.com QQ:824008(长隐) 清除 Cookies - - Archiver - WAP