It would seem trivial:

<?php if(isset($_POST['submit_name']) { echo 'Yahoo!'; } else { echo 'Drawn'; } ?> 

But it was not there. When you press F5 (update), the button always comes down, even if we have not pressed one at all.

    4 answers 4

    Already found a solution to this problem. You can get around this glitch like this in this simple way:

    1. In the form add the element <input type="hidden" value="" name="check" id="check">
    2. Add the following Js-kod:

      document.getElementById("check").value="checked"

    3. In the php script add the following code:

      if(isset($_POST['check'])&&$_POST['check']==checked")
      // ....
      unset($_POST['check']);

    4. profit.

    Well, or yes, FLK, you can search in that way.

    • And if the person Js will be disabled? There are few, but still. Probably it is better to act on the principle of captcha, each time generating a unique id. - tranceman
    • I do not understand. Can you explain the principle again? For each page, generate a unique Id or how? - PaulD
    • one
      Everything is just session_start (); if (isset ($ _ POST ['check']) &&! isset ($ _ SESSION ['unic'])) {$ _SESSION ['unic'] = true; echo 'Yahoo!'; } - FLK
    • Thank you very much. You helped me a lot. - PaulD
     header("Location: ".$_SERVER["PHP_SELF"]); 
    • and this is what forgive? - PaulD
    • This is so that the Post request is not sent again when the page is updated. I slightly changed it. The first time was not quite right. - AseN
    • A, clear. Those. the browser will think that it receives a new document, although in reality it is the same, but all because of the Location redirection to the same address, right? - PaulD
    • one
      Exactly. - AseN

    where it has already been discussed, the reason is that when you press f5 post, the request on some browsers is sent again in full. to prevent this, you need to bind to the session or to something permanent (database, file, cookies) and check for the uniqueness of $ _POST

       echo "<META HTTP-EQUIV='Refresh' CONTENT='1; URL='''>";