Welcome to WebmasterWorld Guest from 54.221.165.245

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

What is the difference between include and require?

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

Junior Member

10+ Year Member

joined:Jan 1, 2006
posts:43
votes: 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?

11:05 pm on June 18, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 20, 2004
posts:1475
votes: 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.

2:45 am on June 19, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Jan 1, 2006
posts:43
votes: 0


where do you start on finding where the error is? I never understood that.
2:49 am on June 19, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 12, 2005
posts:5966
votes: 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 :)

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members