将所有$ _POST []值发送到“nextpage”。

时间:2012-12-02 07:17:29

标签: php html forms post input

假设我在这里使用表单方法POST

有很多值
$_POST["value1"]
$_POST["value2"]
$_POST["value3"]
$_POST["value4"]
$_POST["value5"]
$_POST["value6"]
$_POST["value7"]

我希望将它们发送到nextpage.php

这样做的任何功能?除了使用

<form method="POST" action="nextpage.php">
<input type="hidden" name="value1"  value="value1 />
</form>

5 个答案:

答案 0 :(得分:2)

将您的所有值存储在$_SESSION并在下一页中使用,或者您可以使用这些值创建网址并将您的页面重定向到nextpage.php

答案 1 :(得分:2)

无会话传递

如果没有安全问题且您的帖子数据包含搜索参数等内容。例如$_POST

array('query'=>'keyword', 'orderby' => 'name', 'range' => '4-10' )

您可以使用http_build_query从该数据生成查询字符串,并创建锚标记,供用户点击并将该数据与网址一起传递到下一页。

$url = 'nextpage.php?' . http_build_query($_POST);

它会生成一个类似nextpage.php?query=keyword&orderby=name&range=4-10的网址,您可以在html锚标记中使用,在下一页中,您可以从$ _GET获取它。

使用会话

或者,您可以选择将其存储在$_SESSION中,然后使用销毁session以保持您的网站效果。

答案 2 :(得分:1)

您可以使用Sessioncookie访问其他页面

答案 3 :(得分:1)

要将帖子值传递到下一页,请将完整的$ _POST超全局数组变量存储到会话,然后在下一页上,您可以使用 $ _ SESSION 变量访问这些值p>

或者,您可以使用 curl 使用POST方法将HTTP请求发送到下一页 然后可以使用下一页的$ _POST变量访问这些变量

请参阅下面提到的代码段作为通过curl使用post方法发送HTTP请求的示例

        $url='http://203.114.240.77/paynetz/epi/fts';
 $data = array('login' => '11','pass' => 'Test@123','ttype'  =>'NBFundTransfer','prodid'=>'NSE','amt'=>50,'txncurr'=>'INR','txnscamt'=>0,'clientcode'=>007,'txnid'=>uniqid(),'date'=>date('d/m/Y H:i:s'),'custacc'=>'123456789');
      $datastring = http_build_query($data);
     //die($url.'?'.$datastring);
      $ch=curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_TIMEOUT, 180);
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $datastring);
     $output = curl_exec($ch);
      //echo $output; die;
    curl_close($ch);

答案 4 :(得分:0)

使用此代码。

<!DOCTYPE HTML>
<html>
<head>
<title>First page</title>
</head>
<body onload="document.getElementById('send').submit()">

<form id="send" action="next_page.php" style="display: none;">
<?PHP
foreach($_POST as $key => $val)
{
    echo '<input type="hidden" name="'.$key.'" value="'.$val.'" />';
}
?>
</form>

</body>
</html>
相关问题