I need to restrict a particular php file from directly getting accessed. Not through htaccess any other method please.
3
- 1if you don't want it directly accessed, then DON'T PUT IT IN YOUR DOCUMENT ROOT.Marc B– Marc B2013-08-16 17:33:27 +00:00Commented Aug 16, 2013 at 17:33
- So... through no method? Typically you put things like classes in a private folder.ironcito– ironcito2013-08-16 17:33:41 +00:00Commented Aug 16, 2013 at 17:33
- What are you trying to do? Put a webpage up that people can't access via a web browser?warpedspeed– warpedspeed2013-08-16 17:34:29 +00:00Commented Aug 16, 2013 at 17:34
Add a comment |
3 Answers
I would put a constant inside the root file that loads "childfile". After you try to access the childfile.php directly, it dies on the access error, because that constant is not defined.
Root file:
<?php define('LOADED', TRUE); include('childfile.php'); ... childfile.php:
<?php if( !defined('LOADED') ) die('You cannot access this file directly!'); ...