dongwen1871 2012-01-18 06:35
浏览 99
已采纳

当刷新php页面时,浏览器弹出一条消息给用户[复制]

Possible Duplicate:
Avoid resending forms on php pages

Index.html

 <form method="post" action="demo.php">

             <input type="text" name="fname"/> 
             <input type="text" name="lname"/>
 </form>

demo.php

 <?php
       $firstname = $_POST['fname'];
       $lastname = $_POST['lname'];
       //some more php code to fill the webpage
  ?>

So the user enter his first name and last name and submits the form and then demo.php does its job and its working fine, but when I press F5 or refresh demo.php the next time I get this pop up from the browser

     // this message is from google chrome
     the page that you're looking used information that you entered.
     Returning to that page might cause any action to be repeated.
     Do you want to continute?

    // this message is from IE 7 or 8
    To display the webpage again,Internet Explorer needs to resend information
    you've previously submitted. If you were making a purchase, 
    you should click cancel to avoid duplicate transaction,else click retry.

Why do I get this? I want to just refresh the page. I don't want that message to be popped out from the browser. Just refresh the page according to previously submitted values because its creating duplicate values in my database.

  • 写回答

3条回答 默认 最新

  • douxin8610 2012-01-18 06:40
    关注

    You need to respond with an HTTP redirect, the recommended flow is to process the POSTed data then redirect to another page with an internal identifier of the data processed.

    If you refresh a webpage that has just return from a POST, then the expected behavior is to make another POST with the same values as the last time.

    The header function can be used for that purpose in php http://php.net/manual/en/function.header.php

    To keep the state in the redirection you can use php $_SESSION or passed the data in the query string of the redirected URL.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度