-1

我想知道是否有可能让两个 isset 函数在 1 个 php 文件中工作?如果不是,如何将两个 isset 函数合二为一?有没有更简单的方法来验证数据库中的recaptcha 和激活码?非常感谢,如果有人可以用更简单的方法指导我...

这是我当前的代码 recaptcha 代码:

 if (isset($_POST["recaptcha_response_field"])) {
        $resp = recaptcha_check_answer ($privatekey,
                                        $_SERVER["REMOTE_ADDR"],
                                        $_POST["recaptcha_challenge_field"],
                                        $_POST["recaptcha_response_field"]);

        if ($resp->is_valid) {
                echo "Account activated";
        } else {
                # set the error code so that we can display it
                $error = $resp->error;
                echo "please try again";
        }
} echo recaptcha_get_html($publickey, $error);

我也想验证注册用户的激活码,所以我创建了这个:

if (isset($_GET['success']) === true && empty($_GET['success']) === true)
{
?>
    <h2> Account activated! </h2>
<?php
}
else if (isset($_GET['email'], $_GET['activation_code']) === true)
{
    $email      = trim($_GET['email']);
    $activation_code    = trim($_GET['activation_code']);

    if (emailadd_exists($email) === false)
    {
        $errors[] = 'Email address cannot be found';
    }

    else if (activate($email, $activation_code) === false)
    {
        $errors[] = 'Problem encountered activating your account';
    }

    if (empty($errors) === false)
    {
?>
    <h2> Oops </h2>
<?php
    echo output_errors($errors);
    }
    else
    {
        header('Location: index.php');
        exit();
    }
}
else
{
    echo 'error';
    exit();
}
?>
    <br/>
    <br/>
            <form action="" method="post">
        <ul>
        <li>
            Activation code:<br>
            <input name="activation_code" type="text"><br/>
            <input type="submit" value="Verify" />
        </li>
    </ul>
    </form>

如何结合两个isset函数?还是有更简单的方法...请指导我。提前致谢。

4

2 回答 2

2

如果要在 if 子句中组合两个条件,只需使用 &&。所以这将是

else if (isset($_GET["email"]) && isset($_GET["activation_code"])) {
于 2013-11-02T14:00:16.417 回答
0

更好的是,isset()允许多个参数。

bool isset ( 混合 $var [, 混合 $... ] )

您可以isset()只调用一次,效果相同:

elseif(isset($_GET["email"],$_GET["activation_code"])){

从手册:

$a = "test";
$b = "anothertest";

var_dump(isset($a));     // TRUE
var_dump(isset($a, $b)); // TRUE

unset ($a);

var_dump(isset($a));     // FALSE
var_dump(isset($a, $b)); // FALSE
于 2017-11-28T21:43:03.483 回答