Page 1 of 1
PHP Include
Posted: Fri Jun 16, 2006 10:53 pm
by tecktalkcm0391
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.

Posted: Sat Jun 17, 2006 4:38 am
by anjanesh
Posted: Sat Jun 17, 2006 4:57 am
by technofreak
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
Posted: Sat Jun 17, 2006 9:42 am
by tecktalkcm0391
Thanks it work!
Question though is there anything to put on an included file so say someone goes to included.php. It would print("How did you find this"); otherwise if the file was included it wouldn't do anything. Or is this not possible? Thanks
Posted: Sat Jun 17, 2006 11:39 am
by Christopher
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
But if register_globals is ON this can be circumvented.
Posted: Sat Jun 17, 2006 11:48 am
by printf
Just define a test....
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!
Posted: Sat Jun 17, 2006 2:49 pm
by tecktalkcm0391
thanks it works!