Should I use PHP for header and footer?

Elect

New Member
Hello everyone, nice place you have here :)


I have a small website for my business, right now it has 5 pages but I would like to get it up to 10. The most it will ever have is 15 or so. It is hosting on GoDaddy.

Every page has the same exact header, sidebar, and footer. Since it's a pain right now when I want to change something, it's only going to get harder when I have more pages.

I did some searching on the ways to have a single file for the header and another for the footer so that you only have to change it once. It seems as if doing it with PHP is the best way, but a lot of what I read was 1-3 years old. I am not sure if anything changed.

For example, one article said to use this:

Code:
<?php include("header.php"); ?>

Another article said to use this:

Code:
<?php include 'header.php' ?>

Does it matter? Will one be supported in more browsers?


A second question I had is about changing all my existing pages into .php. My website has already been index by many search engines. I read that I could keep the pages as .htm if I put this into an .htaccess file:

Code:
AddType application/x-httpd-php .html .htm

Is that true? Is there any disadvantage in doing this?

Or should I be looking to do this in a totally different method instead of PHP?

Thank you very much for your help.
 

AsheSkyler

New Member
I use the style with the parentheses, haven't seen the one without them. I do know you might want to always include the semicolon. Weird errors can happen without them. I'm pretty sure that you have to save the files as .php otherwise the php tags won't work.

One thing I did with my site recently that's saved me a lot of update headache is to make one file with the header, footer, navigation, and other common stuff, and then a separate file for the page contents.

In example, the main file:
Code:
<!DOCTYPE HTML>
<html>
<head>Title, Meta, Stylesheet Link, etc.</head>
<body>
Header, Nav, and Sidebar stuff.

<?php echo $content; ?>

Footer stuff here.
</body>
</html>

And the page files themselves:
Code:
<?php
$content="body text, html, and whatnot";
include("main-file.php");
?>

My own files are a bit more lengthy since I assign each page it's own title, keywords, and some other odds and ends. The sad part is that it took me two years of using php before realizing I could do this. I'm a fellow php novice, so there's probably a better way of doin' stuff like this.

Que now the more experienced people to reply. :)
 

kwoods

New Member
One thing I did with my site recently that's saved me a lot of update headache is to make one file with the header, footer, navigation, and other common stuff, and then a separate file for the page contents...

The sad part is that it took me two years of using php before realizing I could do this. I'm a fellow php novice, so there's probably a better way of doin' stuff like this.

:eek: This blows my mind. I usually just do the header/footer files, but I'm totally doing this now! haha. Thank you! :cool:

Also, I use the style with the parentheses too.
 

AsheSkyler

New Member
No prob. =)

Oh yeah, I need to add you might want to watch your quotes in the code. Single quotes for php and double for the html being echoed, or vice versa. I favor using double quotes for everything and I get some interesting broken pages from it when I forget about I'm echoing something. For quotes or apostrophes for normal grammar use, use a reference entity if you think it'll interfere with the coding -> http://www.w3schools.com/tags/ref_entities.asp
 

Frank

New Member
Que now the more experienced people to reply.

It should generally be done more or less the other way around:

HTML:
<!DOCTYPE HTML>
<html>
<head>
    <title>Page titel</title>
    <meta charset="iso-8859-1" />
    <meta name="author" content="your name goes here" />
    <meta name="description" content="blablabla" />
    <link rel="stylesheet" href="x-files/style.css" type="text/css" />
    <script type="text/javascript" src="x-files/pretext-script.js"></script>
</head>
<body>
<?php require("pretext-file.php"); ?>
        <h4>Content title</h4>

        <p>Here I put the content</p>

<?php include("posttext-file.php"); ?>
</body>
</html>

A typical pretext-file.php then contains the nav menu, graphic header, etc. Anything that would come before the content (title) if you would make a website consisting of just one page. Here's an example of what the server then puts together with the three files: www.gezondezorg.org/kem.php.

This way, you can give every page a different title and description, which is essential for a good Google ranking. Also, you can use a different charset if a page needs special characters that are easier done in another. Although that is only necessary in Oriental language sites.
 
Last edited:

Elect

New Member
I ended up doing it differently.

I changed all my pages to .php and removed the complete top and bottom. I replaced it with:

Code:
<?php include 'Header_Sidebar.php' ?>
and
Code:
<?php include 'Footer.php' ?>

Then I put everything into the Header_Sidebar.php and Footer.php page.

Now that you mentioned it, I see that this may be detrimental to my site because each page will have the same meta data. One thing to mention is that my site is not a large content website. It's basically an advertisement for my contracting company. There are currently only 5 pages and in the future there may be a maximum of 10 pages. Since it's so small, will doing it the way I did it still hurt me with SEO?

My concern is that I have keywords for the entire company and what we do. Each page isn't different content like different types of websites, ya know what I mean? One page is the home page, the other page is what we offer, another page is our pricing, then a gallery, then a contact page. So I really can't put keywords to SEO a contact page or a gallery page with some pictures of our work, right? It's still falls under the contracting keywords, correct?
 
Last edited:

Frank

New Member
Keywords indeed play no role in the SEO. But the page title and description most certainly do. They are the first things the Google indexing system looks at, when determining the contents of a page. So with a possible future 10 pages, I would still suggest to stick to the traditional require/include method I gave ya.
 
Last edited:

Elect

New Member
I wouldn't worry about keywords...

Keywords indeed play no role in the SEO.

When I signed up for Google Places it didn't ask me for keywords. I thought that it took the keywords off of the website meta tag?

Or keywords just don't matter at all?

But the page title and description most certainly do. They are the first things the Google indexing system looks at, when determining the contents of a page. So with a possible future 10 pages, I would still suggest to stick to the traditional require/include method I gave ya.

Thanks, will do.


Frank, out of curiosity, shouldn't the content title for the page be in H1 tags? I noticed that in your example it is in H4 tags so i was wondering if I did that incorrectly too :-(
 
Last edited:

Frank

New Member
Frank, out of curiosity, shouldn't the content title for the page be in H1 tags? I noticed that in your example it is in H4 tags so i was wondering if I did that incorrectly too :-(
My principle is this: I like to keep my Hs consistent across the sites I make, with H1 big (3em), and H6 at the normal font size (1em), but bold. With regular intervals in between. Among other things, that keeps the CSS files consistent. Then, I just pick the appropriate H for the content title for that page for that site.

For Google, it doesn't matter. It looks for the biggest H on that page, and labels that the content title. It uses a relative scale, so to speak.

And keywords don't matter at all. Google ignores them, because they are completely redundant. The page title, description, Hs and the page content itself together say it all. And Google has to index all of them anyway.
 
Last edited:

AsheSkyler

New Member
It should generally be done more or less the other way around:

Why exactly?
Not that I think it's the wrong way. I built mine like that for a long time and only reversed it to cut down on how many files were floating around on the computer.
 

Elect

New Member
Frank, thank you very much.


One more question, I see that you use both php include and php require. What is the difference?

Thanks again.
 

Frank

New Member
One more question, I see that you use both php include and php require. What is the difference?

I guess you read Chris's link, that indeed explains it. The reason I use require for the first part is that that part contains the header and the nav menu. Without that, it ain't much of a site, whereas one generally could do without a footer.
 

Elect

New Member
About the keywords that we were discussing before, should I get rid of them? Are they detrimental at all?

I have about 8 electrical phrases that are commonly searched and 8 cities that I work in.
 

chrishirst

Well-Known Member
Staff member
Do the job properly instead, sticking a bunch of "footer links" into every document is last century thinking and is possibly doing more harm than good, as it falls into the "trying too hard" category of "SEO".
 

Elect

New Member
I mean the keywords in the META tags, should I get rid of those? Are they detrimental at all?


Since you brought up footer links, I have a bunch of local towns that I work in listed in the footer, about 1/3 of them are actually links that go to a page that discusses the town. You are saying that is bad too?
 

chrishirst

Well-Known Member
Staff member
I mean the keywords in the META tags, should I get rid of those? Are they detrimental at all?
The 'keywords' meta element hasn't been 'used' by search engines since 2002/2003, so have it, don't have it is not going to make any difference to anything useful.

Since you brought up footer links, I have a bunch of local towns that I work in listed in the footer, about 1/3 of them are actually links that go to a page that discusses the town. You are saying that is bad too?
It's not 'bad' per se, but it is a candidate to call for closer inspection of the documents.

And http://www.youtube.com/watch?v=D0fgh5RIHdE probably not that much use either. Coupled with the fact that there isn't a lot you can say about electrical work in different towns to warrant having separate URL on the topics, so it will appear to be there as SE spam, which if you were honest with yourself ... it is.
 
Top