Bleko Posted June 26, 2007 Share Posted June 26, 2007 How can i find out parent (including) file of included file? Lets imagine that we want to for example auto_prepend file to each file on our server that would write out the name of file its being executed. I know, i can use PHP_SELF but what if i want to write name of file which is already included? I have a web page and i want on it show its name even if it was included, but not the included page itself is showing name but auto_prepend file to each php file, its duty of this auto_prepend_file to write it out i dont want myself to echo it on each page? do you feel me? Quote Link to comment https://forums.phpfreaks.com/topic/57249-how-can-i-find-out-parent-including-file-of-included-file/ Share on other sites More sharing options...
redarrow Posted June 26, 2007 Share Posted June 26, 2007 sorry dont ge ya. do you want to show the current file name on the page. Quote Link to comment https://forums.phpfreaks.com/topic/57249-how-can-i-find-out-parent-including-file-of-included-file/#findComment-282951 Share on other sites More sharing options...
Wildbug Posted June 26, 2007 Share Posted June 26, 2007 You can assign __FILE__ to a variable in the parent file. (You can't in the include because that would return the name of the included file.) Quote Link to comment https://forums.phpfreaks.com/topic/57249-how-can-i-find-out-parent-including-file-of-included-file/#findComment-282974 Share on other sites More sharing options...
Bleko Posted June 26, 2007 Author Share Posted June 26, 2007 To redarrow: Wildbug got me right To: Wildbug thats how i did it but i wanted more excelent solving. But it would make my work easier a lot. Quote Link to comment https://forums.phpfreaks.com/topic/57249-how-can-i-find-out-parent-including-file-of-included-file/#findComment-283003 Share on other sites More sharing options...
jmdoren Posted April 17, 2012 Share Posted April 17, 2012 Yo can use get_included_files(), the first element on the array is the parent file, an example on http://www.codigosonline.com/?p=20 (spanish but easy to understand) Quote Link to comment https://forums.phpfreaks.com/topic/57249-how-can-i-find-out-parent-including-file-of-included-file/#findComment-1338229 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.