shreej21 Posted December 26, 2007 Share Posted December 26, 2007 Hello I have a php file which contain some code. and I donn want anyone can run that file directly through browser. Need Help Its urgent.. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/83208-preventing-file-from-running-through-address-bar/ Share on other sites More sharing options...
Ken2k7 Posted December 26, 2007 Share Posted December 26, 2007 In the file you want to prevent direct access, place something like in the header (meaning at the top, above your codes): <?php if (!defined("_IN_CODE")){ // display error message; user trying to get direct access. Something like: echo "<b>404 - File Doesn't Exist.</b>"; } // your codes here ?> Then in the file you use include or require to call that page, you need to do something like: <?php define ("_IN_CODE", 1); include "URL TO FILE"; // rest of codes here ?> Understand? Quote Link to comment https://forums.phpfreaks.com/topic/83208-preventing-file-from-running-through-address-bar/#findComment-423280 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.