89280/how-to-prevent-direct-access-to-a-php-include-file
I have a php file which I will be using as exclusively as an include. Therefore I would like to throw an error instead of executing it when it's accessed directly by typing in the URL instead of being included.
Basically I need to do a check as follows in the php file:
if ( $REQUEST_URL == $URL_OF_CURRENT_PAGE ) die ("Direct access not premitted");
Is there an easy way to do this?
Hello @kartik,
Add this to the page that you want to only be included
<?php if(!defined('MyConst')) { die('Direct access not permitted'); } ?>
then on the pages that include it add
<?php define('MyConst', TRUE); ?>
Hope it helps!! Thank you!!
PHP is compiled to byte code before ...READ MORE
Hello @kartik, You could use the copy() function : // Will ...READ MORE
Hello @kartik, The following should help realpath — Returns canonicalized ...READ MORE
Simply, $source = 'Source_file_location' ...READ MORE
Hey @kartik, First you have to go to ...READ MORE
Named route is used to give specific ...READ MORE
Hello, This is simple you just need to ...READ MORE
Hey @kartik, Named routing is another amazing feature of ...READ MORE
Hello @kartik, Add this to the page that ...READ MORE
Hii, You can try this: $query="SELECT * FROM CountryInfo ...READ MORE
OR
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.