Forum Moderators: coopster

Message Too Old, No Replies

php include "nav.php";

         

nfinland

10:59 am on Apr 26, 2003 (gmt 0)

10+ Year Member



Hi,

A basic question about php and the use of the include for navigation etc.

If one uses the "include" to put navigation and other elements that are the same on every page should one use html tags like <html>,<head> and <body> in the included file?

The output seems to be the same. Does anybody have comments about how this may affect the search engines when they scan the pages?

Paul in South Africa

11:17 am on Apr 26, 2003 (gmt 0)

10+ Year Member



If you have <head> and <body> tags in your main page they should not be in any include file otherwise the resulting HTML will not validate although it might still display OK in a browser.

nfinland

1:17 pm on Apr 26, 2003 (gmt 0)

10+ Year Member



Thanks for the info - thatīs what I thought!

Birdman

1:28 pm on Apr 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If the resulting document that your script outputs is valid HTML4 [w3.org] , it will validate regardless of whether you include() [php.net] the <head>,<html> or any other tag. However, it's not a good idea to include() [php.net] the main structure of a document. Only include() [php.net] the information that will change from page to page.

Paul in South Africa

3:10 pm on Apr 26, 2003 (gmt 0)

10+ Year Member



Maybe I didn't make myself very clear in my earlier post. What I meant was that if you have <head> and <body> tags in you page and you also have them in your include file you will then end up with 2 sets of <head> and <body> tags in the outputted html which won't validate.

Birdman

3:12 pm on Apr 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Most likely, it won't kill you but why do it if you don't have to?

willybfriendly

3:45 pm on Apr 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



"Only include() the information that will change from page to page."

Hmmm...I commonly include <head> and <body> tags in includes. Allows for something like...

<?
$title = "page_title";
include("header.inc");
echo $copy;
include("footer.inc");
?>

...with header looking like

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><?=$title;?></title>
</head>
<body>
<H!><?=$title;?></H1>

etc......

I use include() to reduce typing repetitive information, it only makes sense to me to use them for the tags that are on every page.

But yes, you have to make sure they only appear once.

WBF