rebel Posted December 21, 2004 Posted December 21, 2004 hi, i'm just wondering what the difference is between 'require' and 'include' in php. just to illustrate my point, 'a.php' includes the following lines <?php function a() { ...... } ?>\n\n\n (which get added every time i edit a file in cpanel for some reason) and in 'b.php', if i use require 'a.php' header("Content-type......... 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. but the problem goes away if i use 'include' instead of 'require'. why is that???? Quote
MikeJ Posted December 21, 2004 Posted December 21, 2004 (edited) Taken directly from PHP.net: 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. 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. Not sure about the header part, maybe someone who codes in it more regularly can chime in. Edited December 21, 2004 by TCH-MikeJ Quote
TCH-Don Posted December 21, 2004 Posted December 21, 2004 If you are going to use the header function you must not output anything even a space before calling it and when you include or require, you have to check each file for any output look for blank lines with a space. its best to put anything you need to output from an included file into a string and then output it after the header function. Cpanels file manager is not the best for editing php. You should get a good text editor. Quote
rebel Posted December 30, 2004 Author Posted December 30, 2004 Cpanels file manager is not the best for editing php.You should get a good text editor. <{POST_SNAPBACK}> yeah think i've got that one sorted out... thanks guys..... and yeah the only reason i edit it in cpanel is because it's probably easier.... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.