This check is basically checking your server referer variable and doing a comparison against the server name and php_self variables. I have seen before where the referer value is overwritten by a client side variable with the same name. When this happens the referer no longer holds the page you were coming from but instead holds the value of this variable.
To test this out you should print out the values before you get to this point like this:
if(isset($_POST)){
die("the value of the referer is: " . $_SERVER["HTTP_REFERER"] . "<br/>the value of the server name and php_self together is: " . urldecode($_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"] . "");
}
This should let you know what the values that are being compared are and why the condition is failing.