php - PHP 重定向出错
问题描述
我将我网站的所有表单提交到特定页面页面,在处理表单数据后,我使用标题功能form_submition.php
重定向到另一个页面,但是在我的一个名为我的表单中,我得到了错误的重定向index.php?page=some page
main_form
if(isset($_POST['form1']))
{
// process form data
header('Location: ../index.php?page=some page')
}
if(isset($_POST['form2']))
{
// process form data
header('Location: ../index.php?page=some page')
}
$to=$_GET['to']
if (isset($_POST['main_form']) ) {
// process form data
}
header("Location: ../index.php?page={$to}&error_loc_{$error_loc}=1&err_msj=" . $err_msj, true, 302);
exit();
但它会将我重定向到mywebsite.com/folders/form_submitions.php?to=all_p
代替mywebsite.com/index.php?page=all_p
有任何想法吗?
更新 1
我检查了很多代码,似乎标题根本没有重定向页面。奇怪的是页面mywebsite.com/index.php?page=all_p
被加载但url不会改变并且css + js文件没有加载,因为相对路径变得无效。
更新 2
进一步检查我的代码,在提交之前main_form
我form_submission.php
用javascript打开一个新窗口来打印一些数据。以下是表格:
<form enctype='multipart/form-data' action='./forms/form_submitions.php?to=all_p' onsubmit="return checkfiles('attachfiles')">
.
.
.
<button id="main_form" name="main_form" class="btn btn-primary">Save Changes</button>
</form>
单击时我调用以下函数#main_form
:
$("#main_form").on('click', function(event) {
newWin = window.open('printingpage.php?data='+ data);
setTimeout(function () { newWin.print(); }, 500);
});
除非关闭打印预览,否则打印功能不会返回。我认为这会产生问题,因为当我删除该newWin.print()
功能时,一切正常。有什么方法可以使这种打印异步?
解决方案
尝试这个。将您的网络链接放在重定向链接中。
$data = array(
'page' => $to,
'error_loc_'.$error_loc => 1,
'err_msj' => $err_msj
);
header("Location: http://www.mywebsite.com/index.php?".http_build_query($data), true, 302);
希望这可以帮助。
推荐阅读
- python - 如何从python中的csv中提取列
- linux - 如何从直线查询结果中的列名中删除表名
- javascript - 在 MERN 应用程序(React 客户端)中外包 API 调用的正确方法?
- sql - 随机化主键与字符值
- javascript - 带有 D3 图表的 React 组件渲染次数过多
- java - 澄清将并行性应用于计算目标单词出现次数的程序意味着什么
- apache-kafka - Kafka Producer 重试尝试
- amazon-web-services - 将 EC2 实例移动到不同的 VPC
- reactjs - 反应使用列表中的 FullCalender
- php - php 函数默认参数传递 bool