首页 > 解决方案 > PHP 重定向出错

问题描述

我将我网站的所有表单提交到特定页面页面,在处理表单数据后,我使用标题功能form_submition.php重定向到另一个页面,但是在我的一个名为我的表单中,我得到了错误的重定向index.php?page=some pagemain_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_formform_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()功能时,一切正常。有什么方法可以使这种打印异步?

标签: phpform-submit

解决方案


尝试这个。将您的网络链接放在重定向链接中。

$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);

希望这可以帮助。


推荐阅读