繁体   English   中英

我正在尝试检查表单的输入,以确保字段不是空白或包含特定单词。 有人知道为什么此代码不起作用吗?

[英]I'm trying to check a form's input to make sure the fields aren't blank or contain specific words. Anyone know why this code isn't working?

这是表单发布到的“ contactprocess.php”文件:

$result = "";
foreach ($_POST as $key => $val) {
if(($val != "") || (strpos($val,'http') == false) || (strpos($val,'seo') == false)){
$result = "clear" ;
}
}

if ($result == '') {
header("location: contact.php");
}

该代码将忽略“ header(“ location:contact.php”);“ 行并继续执行脚本的其余部分。 这怎么写呢?

在尝试重定向的if分支中,您需要exit; 以防止脚本继续执行:

if ($result == '') 
{
   header("location: contact.php");
   exit;
}

暂无
暂无

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

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