PHP page should run once or disable Page refresh

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • inamul
    New Member
    • Sep 2007
    • 8

    PHP page should run once or disable Page refresh

    Hi Guys,

    I have two PHP pages.

    Page 1.
    Page 2.

    I send some data from page 1 to Page 2.

    Page 2 to send an email if record is found.

    But the problem is that if i refresh the page it will send email again and same is repeated.

    How can i stop sending email even if page was refreshed.
  • kovik
    Recognized Expert Top Contributor
    • Jun 2007
    • 1044

    #2
    The best way is to completely remove that page from the history. I'm not sure if you know this, but request data (i.e. POST, GET) are a *part of* the page, so a form and a form with submitted information are actually different pages, even if they have the same source file.

    You'll want to replace the page with the posted information with something else by using the 'Location' header. This will change the current page request so that it no longer "exists" in the user's history, effectively replacing the current page. You can replace it with the same page or with a "thank you" or "success" page.

    Comment

    • Weisbartb
      New Member
      • Aug 2007
      • 36

      #3
      You can also use sessions on page one have it set something like
      [PHP]
      $_SESSION['sendok'] = true;
      [/php]
      And on page two
      [PHP]
      //Before the email is sent
      if($_SESSION['sendok']){
      //Ok send it
      }else{
      }
      session_destroy ();
      [/php]

      Comment

      Working...