Re: Code executed only if .php is not include/require'd
| From: | The Doctor What | Date: | Wed, 07 Jun 2000 05:16:14 +0000 |
| Subject: | Re: Code executed only if .php is not include/require'd | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-1159@lists.php.net to get a copy of this message | ||
* The Doctor What (docwhat@gerf.org) [000604 06:48]:
> Is there a way to have a snippet of code (in my case, call a wrapper
> around show_source) execute only if a normally include/required file
> is *not* inclede/require'd?
>
> Example:
>
> I have a mypage.php which contains the class MyPage. This class is
> only useful if called by other .php files.
>
> I would like to have mypage.php, if called directly (ie, via
> http://docwhat.gerf.org/include/mypage.php ) then it will
> call show_source on itself.
>
> Is this possible?
>
> I was thinking, worst case, something like this:
> if( '/include/mypage.php' != $SCRIPT_NAME ) {
> show_source .....
> }
Well, this is exactly what I did. I still don't like it, I'd rather
have a $0 or something, or a function that returns whether I'm
included or not.
Sort of like __main__ in python.
Anyway, you can see what I did at:
http://docwhat.gerf.org/include/mypage.php
Search for 'magic'.
Ciao!
--
When the only tool you have is a hammer, you tend to treat everything as if it were a nail.
-- Abraham Maslow
The Doctor What: A really hip dude http://docwhat.gerf.org/
docwhat@gerf.org KF6VNC