bitHacker Posted June 23, 2009 Share Posted June 23, 2009 if I require a file... can the required file find which file required him ? for ex. test.php: <? require('inc/db.php'); ?> inside db.php can I know that test.php is the file that required me ? Link to comment https://forums.phpfreaks.com/topic/163415-solved-simple-require-question/ Share on other sites More sharing options...
will35010 Posted June 23, 2009 Share Posted June 23, 2009 Logging it would be the only way I can think of. Link to comment https://forums.phpfreaks.com/topic/163415-solved-simple-require-question/#findComment-862204 Share on other sites More sharing options...
flyhoney Posted June 23, 2009 Share Posted June 23, 2009 test.php: <?php define('TEST', TRUE); db.php: <?php if (defined(TEST)) { echo "required by test.php"; } Link to comment https://forums.phpfreaks.com/topic/163415-solved-simple-require-question/#findComment-862209 Share on other sites More sharing options...
.josh Posted June 23, 2009 Share Posted June 23, 2009 since requiring a file is essentially the same as cut/pasting to php, you can just use basename($_SERVER['PHP_SELF']) or other similar script reference globals inside db.php Link to comment https://forums.phpfreaks.com/topic/163415-solved-simple-require-question/#findComment-862216 Share on other sites More sharing options...
bitHacker Posted June 23, 2009 Author Share Posted June 23, 2009 ok, cool. apparently $_SERVER['SCRIPT_NAME'] gave me the test.php full path (including the file name) so I'm guessing basename($_SERVER['SCRIPT_NAME']) will give me the result i need... thanks guys ! Link to comment https://forums.phpfreaks.com/topic/163415-solved-simple-require-question/#findComment-862222 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.