2013-10-10 44 views

回答

0

您可以使用cUrl发送所需的POST数据,然后进行重定向。

在网上查找:“php curl”。

0

让您form action点要执行的功能和PHP文件那么到底这个地方header("location: your_location_file.php");

第一步 - 提交表单的functions.php
第二步 - 你需要什么都做的submited数据
步骤三 - 重定向

实施例:

<form method="post" action="functions.php"> 
... 
</form> 

functions.ph p

<?php 
... 
all your code 
... 
header("location: your_location_file.php"); 
?> 
+0

这很好,但他希望将发布的数据转移到your_location_file.php。 – idmean

0

如果您不想依靠卷曲,Javascript可以提供帮助。有这个铺设。传入$ _POST或您想要发布的数据的数组。添加错误/参数检查。

function http_post_redirect($url='', $data=array(), $doc=true) { 

    $data = json_encode($data); 

    if($doc) { echo "<html><head></head><body>"; } 

    echo " 
    <script type='text/javascript'> 
     var data = eval('(' + '$data' + ')'); 
     var jsForm = document.createElement('form'); 

     jsForm.method = 'post'; 
     jsForm.action = '$url'; 

     for (var name in data) { 
      var jsInput = document.createElement('input'); 
      jsInput.setAttribute('type', 'hidden'); 
      jsInput.setAttribute('name', name); 
      jsInput.setAttribute('value', data[name]); 
      jsForm.appendChild(jsInput); 
     } 
     document.body.appendChild(jsForm); 
     jsForm.submit(); 
    </script>"; 

    if($doc) { echo "</body></html>"; } 
    exit; 
} 
+0

谢谢你的回答。数组'$ data'看起来应该如何?用这个:'$ data = array( “year”=>“2013”​​, “month”=>“3” );'它不工作。它的重定向,但POST数据不是submited – Mike

+0

必须复制一个旧的,对不起。编辑。 – AbraCadaver

0

您可以使用会话来保存POST数据。

我目前使用的代码如下。在我的第一页加载时,$ _POST数据被检查。如果它包含数据库中已有的某些值,则它将重定向到这些值的页面。

// This could be part of the same script as below, or a different script. 
session_start(); 

if($_POST['my_value'] && valueExistsInMyDb($_POST['my_value'])) { // check my db to see if this is an existing value 

    $id = getIdOfMyValue($_POST['my_value']); // e.g. '4' 

    $_SESSION['POST'] = $_POST; // take ALL post data and save it in the session variable 

    header("location: your.php?myvalue=" . $id); // redirect to bookmarkable target page where $_GET variable matches what was posted. 
    exit(); // ensure no other code is executed in this script after header is issued. 
} 

然后你的其他文件(或者甚至同一文件)可以这样做:

// your.php?myvalue=4 

if(isset($_SESSION) && array_key_exists('POST',$_SESSION)) { 
    $_POST = $_SESSION['POST']; // creates or overwrites your $_POST array with data from the session. The rest of your script won't be able to tell that it's not a real $_POST, which may or may not be what you want. 
    unset($_SESSION['POST']); // you probably want to remove the data from the session. 
} 
// now your myvalue=4 is stored in GET, and you can handle the rest of the POST data as you like 

我不知道这是否是最好的解决方案,但到目前为止,这似乎是工作对我来说迄今为止。我只是在前几天写了代码,并没有测试所有方面。

另一种选择是使用HTML5来更改地址栏。不需要重定向。但缺点是只有“现代Webkit浏览器”可以使用它,显然。