回答
您可以使用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