Page 1 of 1
Php require()
Posted: Thu Jan 13, 2011 6:53 am
by Mince
Hi all
I'd like to know if there's a method where you could see which page used the require() function to call another.
for example:
Now on "newpage.php", i would like to know which page 'called' it.
Thanks
Re: Php require()
Posted: Thu Jan 13, 2011 8:34 am
by Darhazer
if this is run via web, try $_SERVER["SCRIPT_NAME"]; or $_SERVER['PHP_SELF']
Re: Php require()
Posted: Mon Jan 24, 2011 6:12 am
by Mince
I found the answer on yahoo answers:
Code: Select all
$bt = debug_backtrace(); //get the backtrace array
$previouspage = $bt[0]['file']; //outputs the file the current function is in. The current function is require, and that function is in the caller file
this gives the absolute filepath
Here is the link:
http://answers.yahoo.com/question/index ... 112AAC06B0
Re: Php require()
Posted: Tue Jan 25, 2011 5:43 am
by Darhazer
using backtrace is good for debugging purposes, but slow for production
why you need this?