dt2015 2016-04-20 10:55
浏览 48
已采纳

PHP检测重定向到自我

Is it possible to detect a redirect in php, if the redirect was to itelf?

in breif; can I add a line or two of code to the top of my page to first check if the page is a redirect. If it is act on it?

PHP Final line excuted on submit

header("Location: " . $_SERVER['REQUEST_URI']);

HTML Form

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>?submit=true" method="POST">

Still green with php, so learning little by little. Basically I need to control some variables if the page was redirected but only if.

  • 写回答

2条回答 默认 最新

  • dsfds656545 2016-04-20 11:03
    关注

    If you want to prevent form resubmisson on page refresh, then your solution really, really should be to POST the form data to another page that saves the data and then uses a header("Location:...) back to the form. The user will be none the wiser and the refreshing of the form page will never cause a resubmission.

    As a bonus this would also mean you would no longer need to use PHP_SELF. As a piece of bonus advice it's usually far better to use "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'] as PHP_SELF can have extra data added by the browser / user which can cause you issues.

    It is also worth reading up on how to defend yourself against CSRF attacks.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?