Greetings,

I'm new here and new to php. I've always just written in basic html but now want to utilize global header, footer, and left nav bar. From what I've seen I should be able to accomplish that with php.

(My contact with siteaction suggested that I use Frames, but from what I've seen online about them, I'd like to stay away from that option.)

I dropped the code into a test index and uploaded a "header.php" but it didn't pull into my index_test.html.

My site host, siteaction.com is supporting php and mysql, but I have not anything other than upload the files to my directories.

Now, if I can somehow accomplish this with html that's fine too.

Thanks in advance for any help you can give me. toddsmith

In a header file, say header.php, include the HTML you want to have in the header – only the chunk of HTML you plan to insert into the bigger page.

Next, in the index file, use PHP's "include" function to insert the contents of header.php in the appropriate spot like this: <?php include("header.php"); ?> Depending upon your server setup, your index page will probably need to have a the .php extension, ie index.php, otherwise the PHP code won't be parsed and executed.

Hope that's helpful.

Well, it appears that I need to save all my pages as .php if I intend to use it. I had saved my homepage as, index.html

The header.php file loaded in that case and it will not load into the index.html.

Fritz,

Thank-You! That's exactly right! It works now.

Thanks too for the tip about including only the html I need to have placed. Of course I had the <html> and </html> tags...

I appreciate your help and the speed of your reply!

todd smith

If you add this line to your .htaccess file: AddType application/x-httpd-php .html .html pages will be able to execute .php commands. :)

If you add this line to your .htaccess file: AddType application/x-httpd-php .html .html pages will be able to execute .php commands. :)

and every html file will be parsed as php adding a large unneccessary overhead to the server

and every html file will be parsed as php adding a large unneccessary overhead to the server

If I understand the above, you're letting me know that if I save all my pages as .php then it will avoid the "large and unnecessary overhead to the server".

I'm not sure exactly what that means, but I want to keep everything as lean and efficient as I can so it sounds like working with all .php pages is the best solution.

Thanks to all for the suggestions and help. I've never joined a forum like this before because I've always been a "learn as I go" developer (and I use the term loosely) and I've seen been to embarrassed to show how little I really knew.

Thanks for the help and allowing me to build a better site and learn from you all.

todd smith

Actually, I believe he means that ONLY pages that contain PHP code should have .php extensions, so that the PHP gets processed, while HTML files free of PHP code should be saved with .htm or .html suffixes so that they won't be processed by PHP.

By default, most servers will recognize a .php file extension and be sure that the contents of that file get parsed and processed by the PHP engine before they are delivered to end user's browser. Regular HTML files do not need to be run through the PHP engine.

Technically, I should have told you to name your header file header.htm so that it would not be parsed as PHP, but we frequently include PHP code in our headers, nav bars, footers and similar included "parts" of the page, so we are in the habit of giving these "included" files the .php extension. For example, we often have dynamic login information in the header that is handled by PHP code.

Anyway, hope this is helpful info!

coppercup,

OK, I think I'm with you. I'll test that to see how it works. The learning curve is steep! Just when I think I've got it... BAM!
Thanks very much though. You probably just saved me from a big mistake.

todd smith

I meant, what coppercup wrote

keep your html only pages as .html and the php pages as .php
server delays between ,
html d/l directly
or
html parsed through php looking for <?php ?> before being d/l
become significant
adding unnecessary directives to the server, slows it,
server is fast, its not infinite.

In my previous post, I think I was in error about one thing, though, which you hit upon, almostbob.
When using the include() or require() functions, PHP does parse and evaluate any <?php ?> code, regardless of the extension on the included file, in which case it really doesn't matter whether it is header.php or header.html.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.