简体   繁体   English

死与回声的PHP错误信息给我的问题

[英]die vs echo php error message giving me problems

am using recaptcha. 正在使用Recaptcha。 orignally the error was used using 'die' but this took my to another page and gave me an error. 原本该错误是通过'die'使用的,但这将我带到了另一个页面,并给了我一个错误。

because i want it to show in the page, i used print. 因为我希望它显示在页面中,所以我使用了打印。

The problem with echo is the function doesnt work: 回声的问题是该功能不起作用:

this is my site : 这是我的网站:

http://www.the-big-bbq.co.uk/invitation.php#prettyPhoto http://www.the-big-bbq.co.uk/invitation.php#prettyPhoto

my code: 我的代码:

<?php
if (isset($_POST['submit'])){
require_once('recaptchalib.php');
$privatekey = "6LeBwPcSAAAAAL2pNriaDSi8ca0Yb1qewzfDMYyY";
$resp = recaptcha_check_answer ($privatekey,
                            $_SERVER["REMOTE_ADDR"],
                            $_POST["recaptcha_challenge_field"],
                            $_POST["recaptcha_response_field"]);

if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
echo $myDiv1;   

} else {
// Your code here to handle a successful verification
}
}
?>

This is the html 这是HTML

        <p class="myDiv1">Please enter the text shown</p>

originally it was using this: 最初它使用的是:

     die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
     "(reCAPTCHA said: " . $resp->error . ")");

how can i use echo, but show it only when they have entered wrong details. 我如何使用echo,但仅当他们输入了错误的详细信息时才显示它。

All you need to do is output what you want in this situation with one or many echo statements. 您需要做的就是使用一个或多个echo语句输出在这种情况下所需的内容。

I had no idea what $myDiv1 was so I just did it manually. 我不知道$myDiv1是什么,所以我只是手动完成。

Like so:- 像这样:

<?php
if (isset($_POST['submit'])){
    require_once('recaptchalib.php');
    $privatekey = "6LeBwPcSAAAAAL2pNriaDSi8ca0Yb1qewzfDMYyY";
    $resp = recaptcha_check_answer ($privatekey,
                        $_SERVER["REMOTE_ADDR"],
                        $_POST["recaptcha_challenge_field"],
                        $_POST["recaptcha_response_field"]);

    if (!$resp->is_valid) {
        // What happens when the CAPTCHA was entered incorrectly
        echo '<p class="myDiv1">';
        echo "The reCAPTCHA wasn't entered correctly. Go back and try it again.";
        echo ' (reCAPTCHA said: ' . $resp->error . ')';
        echo '</p>'; 

    } else {
        // Your code here to handle a successful verification
    }
}
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM