当前位置:   article > 正文

PHP解决模拟from表单get跳转时,浏览器提示不安全问题_php from 跳转

php from 跳转

原代码:

  1. <?php
  2. /**
  3. * 建立跳转请求表单
  4. * @param string $url 数据提交跳转到的URL
  5. * @param array $data 请求参数数组
  6. * @param string $method 提交方式:post或get 默认post
  7. * @return false show 显示或者隐藏
  8. */
  9. function buildRequestForm($url, $data, $method = 'post', $show = false) {
  10. $html = "<form id='requestForm' name='requestForm' action='" . $url . "' method='" . $method . "'>";
  11. foreach ($data as $key => $val) {
  12. $html.= "<input type='hidden' name='" . $key . "' value='" . $val . "' />";
  13. }
  14. $display = $show ? "style='display:block;'" : "style='display:none;'";
  15. $html.= "<input type='submit' value='确定' " . $display . "></form>";
  16. $html.= "<script>document.forms['requestForm'].submit();</script>";
  17. return $html;
  18. }
  19. //调用示例:
  20. echo buildRequestForm($return_url, $postdata,'get');
  21. exit;

改进方案:

  1. <?php
  2. //使用header跳转,因为模拟Form表单跳转,部分浏览器会提示网址不安全
  3. $return_url = $url."?".http_build_query($data);
  4. header("Location:".$return_url);

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/242220
推荐阅读
相关标签
  

闽ICP备14008679号