[英]Redirect to a webpage using an if statement within an if statement in php, override meta html
如果滿足條件,我想重定向到網頁。
如果不滿足條件,我已經在使用元進行重定向。
<meta http-equiv="refresh" content="4; url=form3.html" />
<?php
$to = "example@example.at";
$subject = "School Info";
$headers = "From: Free Project Day";
$field_school = $_POST['school'];
$field_email = $_POST['email'];
$date = date('d/m/Y');
$forward = "1";
$forward2 ="0";
$location = "index.html";
if (empty($field_school) || empty($field_email) && empty($field_tel) ) {
echo 'Please correct the fields';
return false;
if ($forward == 1) {
header ("Location:$location");
}
}
$msg = "TEXT $date.\n\n";
foreach ($_POST as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "\n";
}
mail($to, $subject, $msg, $headers);
if ($forward2 == 1) {
header ("Location:$location");
}
else {
echo ("TEXT>");
}
?>
我嘗試使用 $forward 但它不起作用。 不使用 Meta 或 $forward 重定向的其他方法是什么?
謝謝
后:
header ("Location:$location");
您需要添加exit();
所以,代碼將是:
header ("Location:$location");
exit();
根據您發布的代碼檢查這是否有效。 我只做了一些編輯。 檢查所有條件是否也符合您的預期
if ((empty($field_school) || empty($field_email)) && empty($field_tel) )
{
echo 'Please correct the fields';
//return false; No need for this as there's not function here
if ($forward == 1)
{
header('refresh:4;url='.$location);
exit();
}
}
$msg = "TEXT $date.\n\n";
foreach ($_POST as $key => $value)
{
$msg .= ucfirst ($key) ." : ". $value . "\n";
}
mail($to, $subject, $msg, $headers);
if ($forward2 == 1)
{
header('refresh:4;url='.$location);
exit();
}
else {
echo "your messages here";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.