Except that does not do what he needs. He needs the including script name in a variable. To do that we need:
index.php:
PHP Code:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
ob_start();
include_once('functions.php');
$contents = ob_get_contents();
ob_end_clean();
echo $contents
?>
functions.php:
PHP Code:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
print_r(get_included_files());
?>
Though this returns the printed array as a string.
After playing with it, I took your solution and modified it and here is a working solution for the poster:
php function:
PHP Code:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
function getIncluder() {
$parentPath = get_included_files();
$parentPath = $parentPath[0];
$parentPath = explode('/',$parentPath);
return end($parentPath);
}
echo getIncluder();
exit;
?>
index.php:
PHP Code:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
include_once('functions.php');
?>
Demo: http://crackfeed.com/inctest/index.php
I am humbled, I should have worked with your idea instead of arguing. Together we found the solution in full.
Bookmarks