Personally I think the following line is way to complicated and could be rewritten because the time taken to debug the script and to ensure it is doing what you want it to do is far in excess of this same script:
Looks like we are going on wrong path. Actually you script is not working end to end . What you want tell me sir, pls clear you code or mention /post in full script. I want if user refresh the page then he will redirect in error page else not.
Why are you programming without using error_reporting, etc.
Try adding this script to the top of your page and if “script is not working end to end” then copy and paste the errors and warnings.
<?php
// THIS MUST BE THE FIRST LINE OTHERWISE ERRORS WILL BE REPORTED
declare( strict_types = 1 ); // REMOVE IF NOT USING PHP 7
ini_set( 'error_reporting', 'true');
error_reporting( -1 ); // MAXIMUM ERROR REPORTING IS BEST
// your script goes here