I am writing a PHP file to be included on a bunch of pages that does authorization checks. I'm using debug_backtrace()
to figure out which page the user is trying to load. I then explode the filepath string and read the last element in that array to get the page name. For some reason, when I use sizeof($referrerArray) - 1
to access the last element, I'm getting the page with a 1 appended. For instance, the page I want is CreateEntry.php
but it echos CreateEntry.php1
. For some reason, when I switch the access variable to (sizeof($referrerArray) - 2
I get the proper behavior but when I echo it, it's the wrong string.
$backtraceArray = debug_backtrace();
$referrerArray = explode('/', $backtraceArray[0]['file']);
$lastElementIndex = sizeof($referrerArray) - 1;
$referrerPage = $referrerArray[$lastElementIndex];
if ($referrerPage != "CreateMenuEntry.php") {
die();
}
print_r($size);
print_r($referrerArray[5]);
print_r($referrerArray[$size]);
my output looks like
"5CreateMenuEntry.phpCreateMenuEntry.php1"
Any ideas?