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: <?php include("header.php"); ?> Code (markup): Another article said to use this: <?php include 'header.php' ?> Code (markup): 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: AddType application/x-httpd-php .html .htm Code (markup): 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.
<?php include 'header.php' ?> works. Adding the parentheses won't make it not work. It works on the server, not in the browser, so it will work in all browsers either way, as long as you have PHP on the server. For GoDaddy that means a Linux server, not a Windows server. If you're currently on a Windows server, they can move you. Call tech support. If you don't know which server you're on, create a file called test.php. Put this in it. <?php phpinfo(); ?> Code (markup): Put the page on your site. Go to http://www.yoursite.com/test.php (where http://www.yoursite.com is your site address). If you have PHP running you'll see a long page listing what functions are available. (You don't care what they are, as long as you get a listing.) If you don't have PHP, you'll just see your file. Adding PHP as an application type won't do anything if PHP isn't running on the site.
Thanks for the reply. I am on a Linux server and I have PHP. So I guess doing this with PHP is the best way? What about renaming the pages to .php? Can I get away with leaving them as .htm or will that cause some type of possible problem?
for your purpose the ' or " doesn't matter. if you are using variables it does matter '$variable' doesn't work '' . $variable . '' does work "$variable" does work hope you learned something!
I use this trick for menus you can do <? @include "menu.php"; ?> and then use folders for different sub areas that way a different menu.php loads for each folder @ suppresses any errors incase there is no menu there!
Out of the box Apache (if you use that) will not process .htm and .html pages as php, so it will cause a problem you CAN howerver change the handler in the apache config to something like addhandler x-httpd-php5 .php .htm .html If your on share hosting ... forget about it. you cant do it. Although you could creatively ad an .htaccess rewrite rule to redirect all .htm requests to their php equivalent so users can still use .htm but they will actualy be loading .php RewriteRule ^(.*).htm /$1.php [R=301,QSA] -- Like my answer? Like my post! Thanks.
if you just use php files for your header footer as well as side bar then you dont have to worry about adding php scripts if needed and also no need to write any htaccess script.
Last time i checked creating a .htm file and putting html code in there will not work... So im confused about your comment.
.htm and .html are the same thing, so putting HTML in an .htm or .html file will work. Putting PHP in an .html (or .htm) file won't work, but putting HTML in a .php file will. (Either put it outside the php tags or echo it - either one will give you the same result.)
This is exactly how I do it. There is no sense in modifying each page when you need to change the header or footer. Or, if you have a central config file included in easch page, just have a variable in there containing the content for the header and footer, then Echo it in place
To better streamline my code, especially when working on projects for clients, a great way to go about headers and footers is to use uri segments to determine where you are and then use if statements to spit out appropriate header and footer info based on the current uri. Example: Say you have an about us page (about.php). In header.php you can check the uri for the presence of about.php and if true, you can then build the meta data based on that to provide a specific title, description, keywords, etc, etc. This way there is only 1 header and 1 footer file and they can generate custom content for any page that utilizes them.
It works to use header/footer and navi in includes() for basic sites I make a Template that has all the include file calls and then I only have to edit the Meta section/Titles. and the body content. It's a fast easy way to get pages up. you can also create an interface Text area for body content and assign it to various article writers etc. They only have to submit the text area and its posted to the body content of the correct page, by writing it to a fwrite txt file and having the includes include the text there. The CSS formatting will already be on the Template page. Yet the writers can add tags like <b> <i> <u> etc if necessary into the text area. Basic faster-function stuffs