Forum Moderators: coopster
1) I use common includes ( <?php require("divleft.html");?> ) but I want to create one that I can change site wide instead of on a directory basis but when I try to make one with the full path, I get errors. How can I do this?
2) On each page, I have a PHP module that adds a PHP generates RSS feed to each page. I want to include the code to invoke this in a PHP include... will having a PHP generated feed within a PHP include, like the one above, cause any problems?... here is what I want to add to the include...
<?php
require_once '/homepages/24/d143989976/htdocs/mydirectory/carp/carp.php';
CarpConf('iorder','link,');
CarpConf('bi','# ');
CarpConf('maxitems',10);
CarpConf('poweredby','<br /><i>Powered by <a href="h##p://www.examplecom">www.example.com</a></i>');
CarpCacheShow('h##p://www.example.com/forum/index.php?act=rssout&id=5');
?>
Thanks for your help and advice.
[edited by: Asia_Expat at 9:26 pm (utc) on April 27, 2007]
[edited by: dreamcatcher at 8:41 am (utc) on April 28, 2007]
[edit reason] Use example.com, thanks. [/edit]
I also changed from 'require' to 'include'... can anyone explain to me the advantage of using 'require' and the fact that it produces a fatal error? Why would you want that?
Also, any comments on my second question in the OP?
[edited by: Asia_Expat at 2:32 am (utc) on April 29, 2007]
>> can anyone explain to me the advantage of using 'require' and the fact that it produces a fatal error?
As you have mentioned, require produces a fatal error if there is a problem. This is useful is you don't want to continue the execution of the following script if the file was not included correctly. In the case of
include, if the file wasn't successfully included a warning will be thrown, however the rest of the script will still execute.
require() and include() are identical in every way except how they handle failure. They both produce a Warning, but require() results in a Fatal Error. In other words, don't hesitate to use require() if you want a missing file to halt processing of the page. include() does not behave this way, the script will continue regardless. Be sure to have an appropriate include_path setting as well.
from php.net/require [php.net]
Can I have includes within and include?
Yes.
I usually include and "include" file. That allows me to update all of my includes in one place.
<?php
/* includes.php lists all files needed for script (A misnomer, since this file is "required" */
require_once("config.php");
require_once("vars.php");
require_once("db-functions.php");
require_once("display-functions.php");
?>
etc.
By doing this I know that all the required scripts have been loaded up, and if they are not, everything comes to a screaching halt.
WBF