homepage Welcome to WebmasterWorld Guest from 54.211.80.155
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
What is the difference between include and require?
aeramas




msg:3371571
 10:51 pm on Jun 18, 2007 (gmt 0)

I had a small site setup and functioning properly on my notebook running SuSE, Apache 2 and php 4.

the code went something like this

<html>
<head></head>
<body>
<?php require('header.php'); /?>

my content

<?php require('footer.php'); /?>

</bdoy>
</html>

When I put it up on my server, there was a parse error with the header file, but when I changed it to include instead of require, it worked fine. I thought the diff was how they handled errors?

 

StupidScript




msg:3371581
 11:05 pm on Jun 18, 2007 (gmt 0)

It's not actually working fine ... you're just not seeing the errors.

"include" says, "Go get that file and put it into the lineup HERE." It doesn't really care whether the file is error-free, or not, and will render the rest of the page if it encounters a "non-fatal" error in the included file.

"require" says, "Go get that file and put it into the lineup HERE, unless there is something wrong with it." An error in a required file will result in a fatal error. That stops everything right there. The file is "required" to be error free, because the rest of the page depends on it.

aeramas




msg:3371710
 2:45 am on Jun 19, 2007 (gmt 0)

where do you start on finding where the error is? I never understood that.

eelixduppy




msg:3371716
 2:49 am on Jun 19, 2007 (gmt 0)

Turn the error_reporting [us.php.net] and and go based on what error you are getting. It will usually specify a line in the code; this is where you want to start looking for errors.

We have a thread on troubleshooting [webmasterworld.com] code in our library. You might want to take a peek :)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved