I am looking for the correct and most secure method of POSTing to the same page without directly defining the page itself. For example not using
<form method="post" action="/mypage.php">
Despite this being a fairly basic usage of PHP, I have found multiple contradictory sources giving advice on how to do this. Currently I simply use
<form method="post" action="">
With some source suggesting (incorrectly?)
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
However after reading more into this, one recommendation suggests using htmlentities()
<form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
I believe this is the most correct method for sanitisation against xss exploits, but was curious is this needed if action=""