3

私は確かにここで何かが欠けているに違いありません。何らかの理由でfilter_varが機能していません。$ _POSTからのメールを検証しようとしていますが、有効なメールでもfalseが返されます。しかし、私が電子メールをハードコーディングすると、それはうまく機能します。どうしたの?

これが私のphpコードです:

function redirect() { //redirecting to home page function. Used in one of the lectures.
    $host = $_SERVER["HTTP_HOST"]; 
    $path = rtrim(dirname($_SERVER["PHP_SELF"]), "/\\");
    header("Location: http://$host$path/index.php");
    exit;
}

try 
{
    $dbh = new PDO($db, $dbuser, $dbpassword);
}
catch (PDOException $e) 
{
    echo "Connection failure: " . $e->getmessage();
}

if (!isset($_POST['email']) || !isset($_POST['password1']) || !isset($_POST['password2'])) {
    redirect();
}

$password1 = htmlspecialchars($_POST['password1']);
$email = htmlspecialchars($_POST['email']);
$password2 = htmlspecialchars($_POST['password2']);
//preg_match('/.+@.+\./', $email) == FALSE



if ($email = "") {
    print "email not there";

} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    print "not real email";

} elseif (strlen($password1) < 6) {
    print("password too small");

}  elseif (!(preg_match('/[A-Za-z].*[0-9]|[0-9].*[A-Za-z]/', $password1))) {
    print "numbers and letters plz";

} elseif ($password1 != $password2) {
    print "passwords not same";
    //redirect();
}
4

1 に答える 1

1

最初のメールチェックを変更します。

if ($email == "") {
    print "email not there";
}

"値をチェックするのではなく、値を取得しています。

于 2012-07-22T06:25:32.003 に答える