Re: [PHP] Include Files self aware?
Or you could try something like this: function isInclude ( $this_scripts_true_location ) { if ( $SCRIPT_FILENAME != $this_scripts_true_location ) { return TRUE; } else { return FALSE; } } On Tuesday 30 April 2002 17:20 pm, you wrote: > // In your config file: > > function selfAwareInclude($filename) { > define($filename, true); > } > > > > // in the file you are making an include > > selfAwareInclude($filename) > include($filename); > > > > > Sincerely, > > Maxim Maletsky > Founder, Chief Developer > > www.PHPBeginner.com // where PHP Begins > > > -Original Message- > > From: mArk.cOLListER [mailto:[EMAIL PROTECTED]] > > Sent: Wednesday, May 01, 2002 2:00 AM > > To: php > > Subject: Re: [PHP] Include Files self aware? > > > > > > The problem with this is you will loose the scope of your variables. > > > > So $filename will not have access to anything from where the function > > is > > > called... > > > > -mark > > > > On Tue, 30 Apr 2002, Billy S Halsey wrote: > > > Try this code (untested): > > > > > > function selfAwareInclude($filename) > > > { > > > define($filename, true); > > > include($filename); > > > } > > > > > > Inside your include file, make calls such as > > > > > > if (defined($filename)) { > > > // Do whatever > > > } > > > > > > Then use the selfAwareInclude() function instead of include(). You > > could > > > > do the same with require, etc. > > > > > > /bsh/ > > > > > > PHP List wrote: > > > > Hi, > > > > Is it possible to detect if a file is being called as an include > > or require? > > > > > ex: > > > > include("file.php")<-- file.php code can "detect" that is has > > been > > > > > called as an include. > > > > > > > > Thanks, > > > > Chris > > > > > > -- > > > > > > > > > /-=[ BILLY S HALSEY > > ]=--\ > > > > | Member of Technical Staff, Sun Microsystems, Inc. ESP Solaris SW > > > | > > > | "All opinions and technical advice offered in this message are my > > > | > > > | own and not necessarily endorsed by my employer." > > > > > > \--=[ [EMAIL PROTECTED] > > ]=/ > > > > -- > > > PHP General Mailing List (http://www.php.net/) > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php -- I know nothing except the fact of my ignorance. Socrates -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Include Files self aware?
// In your config file: function selfAwareInclude($filename) { define($filename, true); } // in the file you are making an include selfAwareInclude($filename) include($filename); Sincerely, Maxim Maletsky Founder, Chief Developer www.PHPBeginner.com // where PHP Begins > -Original Message- > From: mArk.cOLListER [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, May 01, 2002 2:00 AM > To: php > Subject: Re: [PHP] Include Files self aware? > > > The problem with this is you will loose the scope of your variables. > > So $filename will not have access to anything from where the function is > called... > > -mark > > On Tue, 30 Apr 2002, Billy S Halsey wrote: > > > Try this code (untested): > > > > function selfAwareInclude($filename) > > { > > define($filename, true); > > include($filename); > > } > > > > Inside your include file, make calls such as > > > > if (defined($filename)) { > > // Do whatever > > } > > > > Then use the selfAwareInclude() function instead of include(). You could > > do the same with require, etc. > > > > /bsh/ > > > > PHP List wrote: > > > Hi, > > > Is it possible to detect if a file is being called as an include or require? > > > > > > ex: > > > include("file.php")<-- file.php code can "detect" that is has been > > > called as an include. > > > > > > Thanks, > > > Chris > > > > > > > > > > > > -- > > > > > > /-=[ BILLY S HALSEY ]=--\ > > | Member of Technical Staff, Sun Microsystems, Inc. ESP Solaris SW | > > | "All opinions and technical advice offered in this message are my | > > | own and not necessarily endorsed by my employer." | > > \--=[ [EMAIL PROTECTED] ]=/ > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Include Files self aware?
On Tue, 30 Apr 2002, PHP List wrote: > Is it possible to detect if a file is being called as an include or require? > > ex: > include("file.php")<-- file.php code can "detect" that is has been > called as an include. Compare $PHP_SELF with __FILE__, maybe? miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Include Files self aware?
The problem with this is you will loose the scope of your variables. So $filename will not have access to anything from where the function is called... -mark On Tue, 30 Apr 2002, Billy S Halsey wrote: > Try this code (untested): > > function selfAwareInclude($filename) > { > define($filename, true); > include($filename); > } > > Inside your include file, make calls such as > > if (defined($filename)) { > // Do whatever > } > > Then use the selfAwareInclude() function instead of include(). You could > do the same with require, etc. > > /bsh/ > > PHP List wrote: > > Hi, > > Is it possible to detect if a file is being called as an include or require? > > > > ex: > > include("file.php")<-- file.php code can "detect" that is has been > > called as an include. > > > > Thanks, > > Chris > > > > > > > -- > > > /-=[ BILLY S HALSEY ]=--\ > | Member of Technical Staff, Sun Microsystems, Inc. ESP Solaris SW | > | "All opinions and technical advice offered in this message are my | > | own and not necessarily endorsed by my employer." | > \--=[ [EMAIL PROTECTED] ]=/ > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Include Files self aware?
Try this code (untested): function selfAwareInclude($filename) { define($filename, true); include($filename); } Inside your include file, make calls such as if (defined($filename)) { // Do whatever } Then use the selfAwareInclude() function instead of include(). You could do the same with require, etc. /bsh/ PHP List wrote: > Hi, > Is it possible to detect if a file is being called as an include or require? > > ex: > include("file.php")<-- file.php code can "detect" that is has been > called as an include. > > Thanks, > Chris > > -- /-=[ BILLY S HALSEY ]=--\ | Member of Technical Staff, Sun Microsystems, Inc. ESP Solaris SW | | "All opinions and technical advice offered in this message are my | | own and not necessarily endorsed by my employer." | \--=[ [EMAIL PROTECTED] ]=/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Include Files self aware?
Hi, Is it possible to detect if a file is being called as an include or require? ex: include("file.php")<-- file.php code can "detect" that is has been called as an include. Thanks, Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php