du060334 2015-09-25 07:44
浏览 58

在下面的代码中,没有显示验证码图片。 我在代码中没有任何错误,所以我无法理解什么行不正确

generete.php

this page have to make a captcha picture to user but it did not work for me

<?php



    session_start();
        header('Content-Type: image/jpeg');

        $text=$_SESSION['secure'];
        $font_size=30;

    $image_width=200;
    $image_height=40;

    /*use width and height to make image 
    $image=imagecreate($image_width,$image_height);
    imagecolorallocate($image,255,255,255);
    $text_color=imagecolorallocate($image,0,0,0);
    /* add a few lines to hard to reading*/
    for($x=1;$x<=20;$x++){
      $x1=rand(1,100);
      $x2=rand(1,100);
      $y1=rand(1,100);
      $y2=rand(1,100);

      imageline($image,$x1,$x2,$y1,$y2,$text_color);
    }

    imagettftext($image,$font_size,0,15,30,$text_color,'B Elm.ttf',$text);

    imagejpeg($image);

?>

index.php this page check if user enter correct value that shows in picture or not, if is correct show the 'A match.'

     <?php
    session_start();

    if(!isset($_POST['secure'])){
      $_SESSION['secure']=rand(1000,9999);
    }else {
      if($_SESSION['secure']==$_POST['secure']){
        echo'A match.';
      } else{

/*if user enter wrong characters, can refresh and get new code.*/


        echo'incorrect , not match.';
        $_SESSION['secure']=rand(1000,9999);
      }
    }
    ?>

    <img src="generate.php" /> <br>

    <form action="" method="POST">
      type the value you see: <input name="secure" type="text" size="4" maxlength="4">
      <input name="Submit" type="submit" value="Submit">
    </form>
  • 写回答

2条回答 默认 最新

  • doubi1624 2015-09-25 08:05
    关注
     <?php
    $randnum=rand(1000,9999);
    if(isset($_POST['Submit'])){
        $randnumb = $_POST['randnum'];
        $secure = $_POST['secure'];
        if($randnumb==$secure){
            echo'A match.<br/><a href="index.php">refresh</a>';
        }else{
            echo'incorrect , not match.<br/><a href="index.php">refresh</a>';
        }
    }else{
        echo $randnum;
    }
    
    ?>
    
    <form method="POST">
      type the value you see: 
      <input name="randnum" type="hidden" value="<?php echo $randnum; ?>" size="4" maxlength="4">
      <input name="secure" type="text" size="4" maxlength="4">
      <input name="Submit" type="submit" value="Submit">
    </form>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号