87028/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
Hello, In the error callback or $.ajax you have three ...READ MORE
Hello @kartik, If your script is called myScript.js ...READ MORE
Hello @kartik, Try this code : // Create an ...READ MORE
Hello @kartik, Use node-inspector from any browser supporting WebSocket. Breakpoints, ...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.