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条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改