webmaster1 Posted January 11, 2010 Share Posted January 11, 2010 There's an obvious advantage to using php include for the header section of my site: in the future I'd only have to edit the one file. Will it affect search engines or will search engines always detect the parsed code? Any other reason(s) why this might be considered bad practice? Link to comment https://forums.phpfreaks.com/topic/188071-using-php-include-for-header-and-navigation-bad-practice/ Share on other sites More sharing options...
Psycho Posted January 11, 2010 Share Posted January 11, 2010 Search engines cannot detect what code was included and what code was not. Link to comment https://forums.phpfreaks.com/topic/188071-using-php-include-for-header-and-navigation-bad-practice/#findComment-992896 Share on other sites More sharing options...
cags Posted January 11, 2010 Share Posted January 11, 2010 Using includes will not effect SEO at all. When a client (whether it be a person or a crawler/spider) requests a page all they see is the output, it will have no idea whether includes were used or not. Since PHP is a server side technology, this is processed out of the page before the client ever gets to see the content. Link to comment https://forums.phpfreaks.com/topic/188071-using-php-include-for-header-and-navigation-bad-practice/#findComment-992897 Share on other sites More sharing options...
webmaster1 Posted January 11, 2010 Author Share Posted January 11, 2010 Thank you for the explanation. Link to comment https://forums.phpfreaks.com/topic/188071-using-php-include-for-header-and-navigation-bad-practice/#findComment-992930 Share on other sites More sharing options...
webmaster1 Posted January 11, 2010 Author Share Posted January 11, 2010 If I'm using the include function I'll need to use absolute paths. Is there any downside to having to use absolute paths over relative paths (maybe in terms of bandwidth?) Link to comment https://forums.phpfreaks.com/topic/188071-using-php-include-for-header-and-navigation-bad-practice/#findComment-993015 Share on other sites More sharing options...
mattyvx Posted January 11, 2010 Share Posted January 11, 2010 Not a bandwidth issue but one "negative" (depends which way you look at it) about using absolute paths is they will only parse the output of the script. I 'think' that files included from a remote location only include the output of that script, not the variables or functions. I remeber seeing a topic about includes a few months ago and this was one of the things brought up. Link to comment https://forums.phpfreaks.com/topic/188071-using-php-include-for-header-and-navigation-bad-practice/#findComment-993028 Share on other sites More sharing options...
cags Posted January 11, 2010 Share Posted January 11, 2010 Not a bandwidth issue but one "negative" (depends which way you look at it) about using absolute paths is they will only parse the output of the script. I 'think' that files included from a remote location only include the output of that script, not the variables or functions. I remeber seeing a topic about includes a few months ago and this was one of the things brought up. Nobody mentioned including a file remotely, only including files. Any variables declared above an included file can be used in the included file and on the flip side anything declared in the included file can be used below the include statement. If I'm using the include function I'll need to use absolute paths. Is there any downside to having to use absolute paths over relative paths (maybe in terms of bandwidth?) Generally people will use $_SERVER['DOCUMENT_ROOT'], a user defined constant and/or __FILE__ when working with includes. Finding the right mix of these can be a pain and depends entirely on what exactly your attempting to achieve. Link to comment https://forums.phpfreaks.com/topic/188071-using-php-include-for-header-and-navigation-bad-practice/#findComment-993035 Share on other sites More sharing options...
webmaster1 Posted January 11, 2010 Author Share Posted January 11, 2010 @mattyvx: Cheers, but that's going over my head a little. @cags: I've seen shortcut constants like that used in WordPress. I basically have a header section that's universal to every page of the site (including the blog and forum subsections). Based on that criteria should $_SERVER['DOCUMENT_ROOT'] do the trick? I'm not sure why I'd need to find the right mix with the other options you've provided. Link to comment https://forums.phpfreaks.com/topic/188071-using-php-include-for-header-and-navigation-bad-practice/#findComment-993044 Share on other sites More sharing options...
cags Posted January 11, 2010 Share Posted January 11, 2010 Because relative paths can behave differently to what you might expect when used within includes. Link to comment https://forums.phpfreaks.com/topic/188071-using-php-include-for-header-and-navigation-bad-practice/#findComment-993134 Share on other sites More sharing options...
webmaster1 Posted January 11, 2010 Author Share Posted January 11, 2010 I've read up on it in the manual. Makes sense now. Thanks. I'll be using the following for now: <?php include($_SERVER['DOCUMENT_ROOT']."/include/header.html"); ?> Link to comment https://forums.phpfreaks.com/topic/188071-using-php-include-for-header-and-navigation-bad-practice/#findComment-993149 Share on other sites More sharing options...
webmaster1 Posted January 11, 2010 Author Share Posted January 11, 2010 Simply pasting in the absolute path just seems like less hassle though. Link to comment https://forums.phpfreaks.com/topic/188071-using-php-include-for-header-and-navigation-bad-practice/#findComment-993151 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.