hi,<br /><br />i'm just wondering what the difference is between 'require' and 'include' in php.<br /><br />just to illustrate my point, 'a.php' includes the following lines<br /> <?php<br /> function a() {<br /> ......<br /> }<br /> ?>\n\n\n (which get added every time i edit a file in cpanel for some reason)<br /><br />and in 'b.php', if i use<br /><br /> require 'a.php'<br /> header("Content-type.........<br /><br />it would fail because the "\n\n" will be sent before the header, and of course header information can't be sent after there's already been output.<br /><br />but the problem goes away if i use 'include' instead of 'require'.<br /><br />why is that????<!--content-->
Taken <a href="http://us4.php.net/manual/en/function.include.php" target="_blank">directly from PHP.net</a>:<br /><!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->The two constructs are identical in every way except how they handle failure. include() produces a Warning while require()Â results in a Fatal Error. In other words, 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.<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />So basically, require is just a little more strict, and better to use if the included file is required for the rest of the script/page to function properly.<br /><br />Not sure about the header part, maybe someone who codes in it more regularly can chime in.<!--content-->
If you are going to use the header function<br />you must not output anything even a space before calling it<br />and when you include or require, you have to check each file for any output<br />look for blank lines with a space.<br />its best to put anything you need to output from an included file into a string and then output it after the header function.<br /><br />Cpanels file manager is not the best for editing php.<br />You should get a good text editor.<!--content-->
<!--QuoteBegin-TCH-Don+Dec 21 2004, 03:03 PM--><div class='quotetop'>QUOTE(TCH-Don @ Dec 21 2004, 03:03 PM)</div><div class='quotemain'><!--QuoteEBegin-->Cpanels file manager is not the best for editing php.<br />You should get a good text editor.<br /><div align="right"><a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=104757"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />yeah think i've got that one sorted out... thanks guys.....<br />and yeah the only reason i edit it in cpanel is because it's probably easier....<!--content-->
Taken <a href="http://us4.php.net/manual/en/function.include.php" target="_blank">directly from PHP.net</a>:<br /><!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->The two constructs are identical in every way except how they handle failure. include() produces a Warning while require()Â results in a Fatal Error. In other words, 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.<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />So basically, require is just a little more strict, and better to use if the included file is required for the rest of the script/page to function properly.<br /><br />Not sure about the header part, maybe someone who codes in it more regularly can chime in.<!--content-->
If you are going to use the header function<br />you must not output anything even a space before calling it<br />and when you include or require, you have to check each file for any output<br />look for blank lines with a space.<br />its best to put anything you need to output from an included file into a string and then output it after the header function.<br /><br />Cpanels file manager is not the best for editing php.<br />You should get a good text editor.<!--content-->
<!--QuoteBegin-TCH-Don+Dec 21 2004, 03:03 PM--><div class='quotetop'>QUOTE(TCH-Don @ Dec 21 2004, 03:03 PM)</div><div class='quotemain'><!--QuoteEBegin-->Cpanels file manager is not the best for editing php.<br />You should get a good text editor.<br /><div align="right"><a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=104757"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />yeah think i've got that one sorted out... thanks guys.....<br />and yeah the only reason i edit it in cpanel is because it's probably easier....<!--content-->