如何在 php 会话中使用 filter_val 验证电子邮件?
以下是我最近失败的尝试:
if ($_SERVER['REQUEST_METHOD']=="POST") {
if (!empty($_SESSION['email'])) {
if(!filter_var($_SESSION['email'], FILTER_VALIDATE_EMAIL)) {
echo "Required: valid e-mail address";
} else {
echo "Your email is " . $_SESSION['email'] . "<br />";
}
} else {
echo "Required: valid e-mail address";
}
}
// 当变量为空时,我收到正确的消息,但如果我输入无效或有效的电子邮件,则不会有任何回显。我一整天都在做这个。
The following is my most recently failed attempt:
if ($_SERVER['REQUEST_METHOD']=="POST") {
if (!empty($_SESSION['email'])) {
if(!filter_var($_SESSION['email'], FILTER_VALIDATE_EMAIL)) {
echo "Required: valid e-mail address";
} else {
echo "Your email is " . $_SESSION['email'] . "<br />";
}
} else {
echo "Required: valid e-mail address";
}
}
// When the variable is empty, I get the correct message, but if I enter an invalid or valid e-mail, nothing echoes. I have been at this all day.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是旧帖子,但这会有所帮助。
该函数使用filter_var并检查电子邮件是否具有“超级域”。
Is old post but this will help.
This function use filter_var and check if email have "super domains".