问题描述
此contact.php 表单正在处理提交,然后重定向到新页面,然后突然停止工作.我尝试添加错误处理并将标题移动到所有其他标题的顶部,但两者都不起作用.表单仍在按预期提交数据,只是重定向不起作用.任何想法将不胜感激.
This contact.php form was working to handle a submit and then redirect to a new page and then all of a sudden just stopped working. I have tried adding error handling and also moving header to the top in front of all other, but neither works. The form is still submitting the data as expected, it's just the redirect that doesn't work. Any ideas would be appreciated.
<?php
include 'config.php';
$post = (!empty($_POST)) ? true : false;
if($post)
{
$email = trim($_POST['email']);
$subject = "Downloaded Course Units";
$error = '';
if(!$error)
{
$mail = mail(WEBMASTER_EMAIL, $subject, $message,
"From: ".$email."
"
."Reply-To: ".$email."
"
."X-Mailer: PHP/" . phpversion());
if($mail)
{
echo 'OK';
header('location: http://www.google.com.au/');
exit();
}
}
}
?>
推荐答案
使用javascript.
Use javascript.
代替
header('location: http://www.google.com.au/');
使用,
?>
<script type="text/javascript">
window.location.href = 'http://www.google.com.au/';
</script>
<?php
即使你的浏览器有输出,它也会重定向.
It will redirect even if something is output on your browser.
但是,要采取一项预防措施:即使页面上打印了某些内容,Javascript 重定向也会重定向您的页面.
But, one precaution is to be made: Javascript redirection will redirect your page even if there is something printed on the page.
确保它不会跳过任何用 PHP 编写的逻辑.
Make sure that it does not skip any logic written in PHP.
这篇关于在 PHP 中重定向而不使用 header 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)