title: PHP - self form post and exit
body: <p>I actually have multiple questions. But they are related.</p>
  
  <p>First is, is it a bad practice to submit forms using self posts? Does it have any bad security issues? The reason why i decided to use self posts was because i did not want to reveal file/folder structures and server side programming language i am using.</p>
  
  <p>For example, this clearly shows that i am using php and that the logout.php file is inside a logout folder on the sibling level.</p>
  
  <pre><code>&lt;form action="../logout/logout.php" method="post"&gt;
     //form elements goes here
  &lt;/form&gt;
  </code></pre>
  
  <p>With this example, i don't show what server side language i am using but a programmer clearly knows that it is a self post and that the logic have to go through itself first:</p>
  
  <pre><code>&lt;?php
    if (isset($_POST['log_out']))
    {
       // do some stuff
    }
  ?&gt;
  &lt;form method="post"&gt;
     //form elements goes here
  &lt;/form&gt;
  </code></pre>
  
  <p>The consequence of having a self post as i realized, is that i have to have a complicated logic at the beginning of every self post the page. These logics will have to select the right code of execution, sometimes redirect me and stop from executing the rest of the code.</p>
  
  <p>For example, here i have a page that does multiple things and posts to itself. In order to stop executing the rest of the code or html bellow again i need use the php function "exit".</p>
  
  <pre><code>&lt;?php
    if (isset($_POST['add_two_numbers']))
    {
       // code for adding two numbers
       exit();
    }
    else if (isset($_POST['add_three_numbers']))
    {
       // code for adding three numbers
       exit();
    }
    else if (isset($_POST['log_out']))
    {
       // destroy session and data before logging out
       header("location: ./logout/logout.php");
       exit();
    }
  
    // php code that should happen if there is no post logic and
    // will be unapropiately executed if exit is not used
  ?&gt;
  
  &lt;html&gt;
    &lt;head&gt;
       &lt;script&gt;
       function init()
       {
           // will do stuff if php did not exit properly
       }
  
       // more js code
  
       window.onload = init;
  </code></pre>
  
  <p>So, i have to use php command exit which i read so much about how it causes problem and it is bad and some suggest use return instead. However, the problem with return is that it doesn't always stop the code from continue executing specially the html part. So is there any better way of doing this?</p>
  
  <p>Thanks.</p>