一口一个菠萝 2016-04-06 02:32 采纳率: 50%
浏览 1715
已采纳

信息查询页面,怎么加入验证码

查询信息用的页面,php写的验证码,现在只能判断验证码是否正确,不能进行下一步操作。比如我输入了要查询的内容,再输入验证码,然后提交就只能判断验证码是否正确,不能查询到信息。要怎么写才能在判断验证码正确后,显示出相关信息呢。现在所有内容都做好了,没有验证码是可以查询的,问题就在验证码这一块儿

  • 写回答

2条回答

  • 法如果日ugri 2016-04-06 15:11
    关注

    我大概明白你的问题。Follow me……
    在这里写几个php文件来演示吧,一个是展示页index.php,另两个是处理文件index_ok.php、vcode.php。
    index.php的代码如下:

    function chkinput(form){ if(form.user.value==""){ alert("用户名不能为空!"); form.user.focus(); return false; } if(form.pwd.value==""){ alert("密码不能为空!"); form.pwd.focus(); return false; } if(form.vcode.value==""){ alert("验证码不能为空!"); form.vcode.focus(); return false; } if(form.vcode.value!=form.ycode.value){ alert("输入的验证码不正确!"); form.vcode.focus(); return false; } return true; }








    用户名:

    密 码:

    验证码:

              var num1=Math.round(Math.random()*10000000+10000); var num=num1.toString().substr(0,4); document.write("<img name=c src='vcode.php?code="+num+"'>"); f.ycode.value=num; function recode(){ var num1=Math.round(Math.random()*10000000); var num=num1.toString().substr(0,4); document.c.src="vcode.php?code="+num; f.ycode.value=num; } 看不清?

          注册


    接下来是处理文件index_ok.php和vcode.php。先看index_ok.php,代码如下:
    <?php
    header("content-type=text/html;charset=utf8");
    include_once("conn.php");
    $name=$_POST['user'];
    $mima=$_POST['pwd'];
    $r=mysql_query("select * from tb_admin where user='".$name."' and pwd='".$mima."'",$conn);//数据库的数据自己添加,这里我就不说了。
    if(mysql_num_rows($r)>0){

    echo "alert(&#39;登陆成功!&#39;);location=&#39;xxx.php&#39;;";
    }else{

    echo "alert(&#39;用户名或密码错误,请重试!&#39;);location=&#39;index.php&#39;;";
    }
    ?>
    再看vcode.php,代码如下:
    <?php

    header("Content-type:text/html;charset=utf8");

    $im=imagecreate(60,20);

    imagefill($im,0,0,imagecolorallocate($im,200,200,200));

    $code=$_GET['code'];

    for($i=0;$i<4;$i++){

    $color=imagecolorallocate($im,rand(0,100),rand(0,100),rand(0,100));
    
    imagestring($im, rand(3,5),60*$i/4+rand(3,6), rand(0,6), $code[$i], $color);
    

    }

    for($j=0;$j<200;$j++){

    imagesetpixel($im,rand(0,60),rand(0,20),imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255)));
    

    }

    imagepng($im);

    imagedestroy($im);

    运行得到
    Bingle!提交既能判断验证码是否正确,又能查询到信息。
    希望我的解答能帮到你,如果还有什么疑问可以继续问我。
    Love code,love life.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条