Forum Moderators: coopster

Message Too Old, No Replies

PHP Includes - Any pitfalls?

PHP Newbie Question

         

Mr_N

4:49 pm on May 2, 2006 (gmt 0)

10+ Year Member



I'm doing some overhauling on my site, and will be including php includes for the header, footer, and possibly the ad banners, and wanted to make sure if there may be some pitfalls in going this route.

My main concerns are any potential problems with search engines crawling these pages. Is there anything I should consider to make sure they find all the links in the header, since that's where my navigation bar will be?

If I'm going to use 3 or 4 includes on a page, each referencing a different page, is there still a need for include_once or require_once?

Anything else I should know about? Sorry about the newbie-ish question, but any insight one can lend would be fabulous. :)

jatar_k

9:59 pm on May 2, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you don't need to worry about includes causing issues with search engines as they only see the final output after all the php is processed

for header and footer type includes I just use include as opposed to the 'once' functions. The once functions are great for including libraries but aside from that I don't worry about them.

>> anything else

remember that includes work on the file system and have no clue about your website structure. So you include files absolutely from the root of the server not the root of your website. I have seen this problem a lot.

another tip, you can make your sites more portable if you use $_SERVER['DOCUMENT_ROOT'] this means you won't have to swicth includes if you move servers.

example

if you have header.php located in the root of your site and need to include it through out your site you would do this

include '/example/public_html/header.php';

where the root of your website is located at /example/public_html/

but this is easier

include $_SERVER['DOCUMENT_ROOT'] . '/header.php';

same thing but the first would have to be changed if the location of your site's root changed