回答
您可以使用cUrl
發送所需的POST數據,然後進行重定向。
在網上查找:「php curl」。
讓您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");
?>
這很好,但他希望將發佈的數據轉移到your_location_file.php。 – idmean
如果您不想依靠捲曲,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;
}
謝謝你的回答。數組'$ data'看起來應該如何?用這個:'$ data = array( 「year」=>「2013」, 「month」=>「3」 );'它不工作。它的重定向,但POST數據不是submited – Mike
必須複製一箇舊的,對不起。編輯。 – AbraCadaver
您可以使用會話來保存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瀏覽器」可以使用它,顯然。
- 1. 提交表單並重定向頁面
- 2. 提交數據並重定向到PayPal
- 3. 使用POST重定向GET頁面數據到另一頁
- 4. 重定向到頁面表單提交,並使用表單數據在
- 5. Php重定向到POST數據的另一個頁面
- 6. 重定向到使用其他頁面,並使用POST發送數據
- 7. 重定向到新頁面並設置POST數據
- 8. POST提交失敗並重定向
- 9. 使頁面等待提交重定向
- 10. POST數據重定向頁面無法
- 11. 插入表單數據到MySQL,提交按鈕重定向到PHP頁面,並沒有數據到SQL
- 12. php post動態重定向並阻止表單重新提交
- 13. PHP重定向到基於選擇的表單提交頁面
- 14. PHP重定向到不同的頁面表格後提交
- 15. 重定向到PHP頁面使用jQuery
- 16. Django重定向到頁面並提交表單?
- 17. php post和重定向頁面同時
- 18. FIX-Php表單提交警報重定向到其他頁面
- 19. PHP提交表單後重定向到新頁面
- 20. 無法將表單提交頁面重定向到php
- 21. 設置表單重定向到提交當前頁面(SilverStripe/PHP)
- 22. PHP,JQuery表單提交重定向到另一個頁面
- 23. Javascript - 用POST數據重定向到頁面
- 24. 如何使用POST數據重定向頁面
- 25. Ajax表單提交頁面重定向
- 26. 提交表格後重定向頁面
- 27. 提交事件不重定向頁面
- 28. 點擊提交後重定向頁面
- 29. POST數據和重定向到同一頁面的CakePHP
- 30. 表單重新提交在PHP中,如何重定向到特定頁面
重定向並立即發佈? – vbrmnd