php 带有验证码的简单联系表单 HTML?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22573639/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:06:48  来源:igfitidea点击:

Simple contact form HTML with Captcha?

phphtmlformscontactspam-prevention

提问by 5AMWE5T

I am looking for a simple HTML for a contact form that has ReCaptcha or some type of anti-spam features. I tried multiple tutorials but they are all complicated and I can't get any to work. All I need is an Name, Email, and Message field (and also the ReCaptcha and submit button). Does anyone know where I can find a simple contact form HTML?

我正在为具有 ReCaptcha 或某种类型的反垃圾邮件功能的联系表单寻找一个简单的 HTML。我尝试了多个教程,但它们都很复杂,我无法使用任何教程。我只需要一个姓名、电子邮件和消息字段(以及 ReCaptcha 和提交按钮)。有谁知道我在哪里可以找到一个简单的联系表单 HTML?

采纳答案by Professor

If you have been struggling to implement recaptcha just go for

如果你一直在努力实现 recaptcha,那就去吧

$a=rand(2,9); // this will get a number between 2 and 9
$b=rand(2,9); // this will also get a number between 2 and 9. You can change this according to your wish

$c=$a+$b;

On the php page just show

在 php 页面上只显示

echo $a."+".$b."="<input type="text" name="recaptcha" />

and check whether the textbox value is equal to $c.

并检查文本框值是否等于 $c。

This is the most simple recaptcha sort of thing you can implement to prevent bots.

这是您可以实施的最简单的 recaptcha 类型的事情来防止机器人。

回答by Professor

Try thissmall script: You can easily use it in forums as

试试这个小脚本:您可以轻松地在论坛中使用它作为

<img src="tools/showCaptcha.php" />
<input type="text" name="captcha"/>

and it will store captcha value in an session variable example

它将在会话变量示例中存储验证码值

if ($_POST["captcha"] == $_SESSION['captcha']) { ... } else { ... }

回答by Jay Patel

Step 1

第1步

  • You need some code to generate a graphical font image representation web captcha. you must have GD libraryfor generating font image.

    <?php
        session_start();
        $RandomStr = md5(microtime());
        $ResultStr = substr($RandomStr,0,5);
        $NewImage =imagecreatefromjpeg("bgimage.jpg");
    
        $LineColor = imagecolorallocate($NewImage,233,239,239);
        $TextColor = imagecolorallocate($NewImage, 255, 255, 255);
        imageline($NewImage,1,1,40,40,$LineColor);
        imageline($NewImage,1,100,60,0,$LineColor);
    
        $font = imageloadfont("font.gdf");
        imagestring ($NewImage, $font, 5, 5, $ResultStr, $TextColor ); 
        $_SESSION['originalkey'] = $ResultStr;  //store the original coderesult in session variable
    
        header("Content-type: image/jpeg");
        imagejpeg($NewImage);
    ?>
    

    Step 2

  • Now your form to call captcha.

    <form action="submit.php" method="post" name="form1">
        Name:
        <input type="text" name="name" value="" /> <br />
        Email Address:
        <input type="text" name="email" value="" /> <br />     
        Message:
        <textarea name="message" cols="30" rows="6"></textarea> <br />
        <img src="php_captcha.php" />
        <input name="captcha" type="text" id="captcha" size="15" /> <br />
    
        <input type="submit" name="submit" value="Submit" />
        <input type="reset" name="reset" value="clear"/>
    </form>
    
  • 您需要一些代码来生成图形字体图像表示网络验证码。你必须有GD 库来生成字体图像。

    <?php
        session_start();
        $RandomStr = md5(microtime());
        $ResultStr = substr($RandomStr,0,5);
        $NewImage =imagecreatefromjpeg("bgimage.jpg");
    
        $LineColor = imagecolorallocate($NewImage,233,239,239);
        $TextColor = imagecolorallocate($NewImage, 255, 255, 255);
        imageline($NewImage,1,1,40,40,$LineColor);
        imageline($NewImage,1,100,60,0,$LineColor);
    
        $font = imageloadfont("font.gdf");
        imagestring ($NewImage, $font, 5, 5, $ResultStr, $TextColor ); 
        $_SESSION['originalkey'] = $ResultStr;  //store the original coderesult in session variable
    
        header("Content-type: image/jpeg");
        imagejpeg($NewImage);
    ?>
    

    第2步

  • 现在您的表单调用验证码。

    <form action="submit.php" method="post" name="form1">
        Name:
        <input type="text" name="name" value="" /> <br />
        Email Address:
        <input type="text" name="email" value="" /> <br />     
        Message:
        <textarea name="message" cols="30" rows="6"></textarea> <br />
        <img src="php_captcha.php" />
        <input name="captcha" type="text" id="captcha" size="15" /> <br />
    
        <input type="submit" name="submit" value="Submit" />
        <input type="reset" name="reset" value="clear"/>
    </form>
    

Step 3

第 3 步

  • Now this is last step to form submiting time check capcha validation. Using session information.

    <?php
          $originalkey = substr($_SESSION['originalkey'],0,5);  //session of captcha
          $captcha = $_REQUEST['captchacode'];
          if($captcha!=$originalkey){
            print_error("<b> Captcha does not match, Go back and try again.</b>");
          }
    ?>
    
  • 现在这是表单提交时间检查验证码验证的最后一步。使用会话信息。

    <?php
          $originalkey = substr($_SESSION['originalkey'],0,5);  //session of captcha
          $captcha = $_REQUEST['captchacode'];
          if($captcha!=$originalkey){
            print_error("<b> Captcha does not match, Go back and try again.</b>");
          }
    ?>
    

Hope this help you!

希望这对你有帮助!

回答by Junaid

Visit here this might solve your problem.Its simple form with explanation.

访问这里这可能会解决您的问题。其简单的形式与解释。

http://www.html-form-guide.com/contact-form/html-contact-form-captcha.html

http://www.html-form-guide.com/contact-form/html-contact-form-captcha.html