gpt4 book ai didi

php - FILTER_VALIDATE_EMAIL 无效

转载 作者:搜寻专家 更新时间:2023-10-31 21:40:37 25 4
gpt4 key购买 nike

我肯定在这里遗漏了一些东西。由于某种原因 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();
}

最佳答案

更改第一封电子邮件检查:

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

它正在获取值 " 而不是检查它。

关于php - FILTER_VALIDATE_EMAIL 无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11598131/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com