doujiang1939 2013-06-10 16:25
浏览 89

php_self和重定向在同一页面

Is it ok or standard to use $_SERVER['PHP_SELF']; and header('Location: http://www.example.com/form.php'); in the same page to avoid resubmitting the form on refresh.

I understand the concept of using $_SERVER['PHP_SELF']; on a page with a form, but then if I use header('Location: http://www.example.com/form.php'); to avoid resubmitting to the db should I be redirecting to the same page.

I'm kinda confused.

UPDATE: Making it a bit more clear

I don't want to use the processing file name in form action (future proof - filename change, etc.), hence the use of $_SERVER['PHP_SELF'] but now hitting refresh resubmits the form. To avoid that we go the PRG route, but redirecting it to the same page $_SERVER['PHP_SELF'] is not solving the issue.

I wonder how others are doing it. Bottom line, I want to have my form and processing it in the same page without resubmission on refresh.

  • 写回答

1条回答 默认 最新

  • doutang2017 2013-06-10 16:30
    关注

    This pattern is known as Post/Redirect/Get.

    You should redirect to that page that processes the input data, for example if your form action is $_SERVER['PHP_SELF']; you process the input data on the same page, so you redirect to the same page, if you want to process the input data on another page, than redirect to that page.

    So, if

    should I be redirecting to the same page.

    is a question. the answer is yes. And you maybe want to add some GET variables to show a "successfully sent" message, or something like that.

    评论

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)