Drew_13 Posted February 27, 2008 Share Posted February 27, 2008 hey, i have a newb question about a php environment. i set up a file called html.inc, and i am trying to put multiple functions in it, to use on my index page. however i keep getting an error. here's what my html.inc looks like: <? /* * Created on Feb 21, 2008 * */ function header() { ?> <html> <head> </head> <body> <? } function footer() { ?> </body> </html> <? } ?> and this is what i have regarding this file in my index.php: <?php require("include/html.inc"); header(1); footer(); ?> and it gives me this error: Fatal error: Call to undefined function footer() in C:\Program Files\php_workspace\index.php on line 9 i would like to be able to use more than even just two functions in this file, and perhaps have other include files in the future. do you know what would cause this error? thanks alot! Link to comment https://forums.phpfreaks.com/topic/93249-newbie-question-about-include-file/ Share on other sites More sharing options...
cooldude832 Posted February 27, 2008 Share Posted February 27, 2008 why must they be functions why not just output the raw data in the file i.e header.php <html> <head> </head> <body> Footer.php </body> </html> Anypage.php <?php require_once("header.php"); echo "Hello World!"; require_once("footer.php"); ?> works a lot simpler for you Link to comment https://forums.phpfreaks.com/topic/93249-newbie-question-about-include-file/#findComment-477644 Share on other sites More sharing options...
DyslexicDog Posted February 27, 2008 Share Posted February 27, 2008 I've got a guess... it's possible your apache doesn't parse .inc files try renaming your file html.inc.php see if that helps. Link to comment https://forums.phpfreaks.com/topic/93249-newbie-question-about-include-file/#findComment-477663 Share on other sites More sharing options...
PFMaBiSmAd Posted February 27, 2008 Share Posted February 27, 2008 The file name and extension used for include/require files does not matter (except that the raw content of files not ending in .php can be seen by browsing to them, assuming you know or can guess the file name.) The original problem is that the included/required file is not using full php open tags <?php so the content is not being parsed as php code. The main file is using full <?php tags. Drew_13, you need to be consistent and always use full <?php tags. The next problem is that header() is a built in php function and you cannot name a user written function the same. Link to comment https://forums.phpfreaks.com/topic/93249-newbie-question-about-include-file/#findComment-477689 Share on other sites More sharing options...
cooldude832 Posted February 27, 2008 Share Posted February 27, 2008 I feel like an idiot not realizing that. I too questioned why header() phrased and not footer() then realizing after what u wrote that was the issue:) Link to comment https://forums.phpfreaks.com/topic/93249-newbie-question-about-include-file/#findComment-478037 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.