原代码:
<?php
/**
* 建立跳转请求表单
* @param string $url 数据提交跳转到的URL
* @param array $data 请求参数数组
* @param string $method 提交方式:post或get 默认post
* @return false show 显示或者隐藏
*/
function buildRequestForm($url, $data, $method = 'post', $show = false) {
$html = "<form id='requestForm' name='requestForm' action='" . $url . "' method='" . $method . "'>";
foreach ($data as $key => $val) {
$html.= "<input type='hidden' name='" . $key . "' value='" . $val . "' />";
}
$display = $show ? "style='display:block;'" : "style='display:none;'";
$html.= "<input type='submit' value='确定' " . $display . "></form>";
$html.= "<script>document.forms['requestForm'].submit();</script>";
return $html;
}
//调用示例:
echo buildRequestForm($return_url, $postdata,'get');
exit;
改进方案:
<?php
//使用header跳转,因为模拟Form表单跳转,部分浏览器会提示网址不安全
$return_url = $url."?".http_build_query($data);
header("Location:".$return_url);