Sometime you might face a saturation with you do not want a user to browser/call your PHP file. In that case obviously you need some kind of protection. Just use this below code to protect your PHP file from direct call. Put this at the top of your PHP file which you would like it to be protected from direct call/browse.
if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) { die('You are not allowed to call this page directly.'); }
Tags: php, protect direct call
Recent Comments