| Sometimes you want to be able to give some feedback if a PHP include has failed. Here is a version using the fopen command, which can search the include path.
<?php
$includefile="foo.php";
//using fopen to verify file. the third parameter triggers include_path search
$handle = fopen($includefile, "r", 1);
if ($handle) {
fclose($handle);
include ($includefile);
} else {
echo "file: $includefile not found in path";
echo "handle is: $handle";
}
?>
Here's another example much better simple than the above. As you can see, just add @ in front of the function you will use. By '@', the error message will be ignored. (not be shown)
<?php
include "foo.php";
?>
If you just want to include one time only, you'd better use require_once: <?php
require_once "foo.php";
?>
|