I can't find anything in google. I really looked this time.
PHP Include
Moderator: General Moderators
- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
PHP Include
Is it possible for PHP to tell if it is included and if not display it displays a message?
I can't find anything in google. I really looked this time.
I can't find anything in google. I really looked this time.
- technofreak
- Forum Commoner
- Posts: 74
- Joined: Thu Jun 01, 2006 12:30 am
- Location: Chennai, India
- Contact:
If you wanna find whether the codes in include file is working correctly use require. If the include file is missing or something is wrong with that, then the whole process gets stopped where the error occured. include() produces a warning while require() produces a fatal error. Otherwise, both include() and require() behaves in the same way. http://in2.php.net/manual/en/function.include.php
- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Code: Select all
<?php
if (! isset($a_variable_that_is_set_in_the_including_script)) {
print("How did you find this");
exit;
}
/ the rest of the include file(#10850)
Just define a test....
pif!
Code: Select all
// main script....
/*
* include file test
*/
define ( 'IS_INCLUDE', true );
// place at the top of all include scripts!
/*
* file can only be included
*/
if ( ! defined ( 'IS_INCLUDE' ) ) { exit (); }pif!
- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida