I have a php script, and i'd like it so that it will only show this certain text if you're viewing the page in your browser, and it's not included by another script..
For example
//foo.php
<?php
if(!included){
echo "You can only see this if this is the page you're viewing";
}
?>
//bar.php
<?php
include 'foo.php';
?>
Now, When you view "bar.php", you should not see the text.. But if you open foo.php instead, you will.. How would i do this..? If at all possible..
Not possible per se, but if you are exposing the php page on a website, e.g. example.com/bar.php
, you can check $_SERVER['SCRIPT_FILENAME']
if you are using apache.
if (basename(__FILE__) != basename($_SERVER['SCRIPT_FILENAME'])) {
//this is included
}
In bar.php:
<?php
$included = true;
include 'foo.php';
?>
In foo.php:
if(!isset($included)){
echo "You can only see this if this is the page you're viewing";
}
You should see about array get_included_files(void)
http://php.net/manual/en/function.get-included-files.php
It gives you a list of the included files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With