include files

Thread Solved

Join Date: May 2009
Posts: 10
Reputation: toddsmith is an unknown quantity at this point 
Solved Threads: 0
toddsmith toddsmith is offline Offline
Newbie Poster

include files

 
0
  #1
May 28th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 6
Reputation: coppercup is an unknown quantity at this point 
Solved Threads: 1
coppercup's Avatar
coppercup coppercup is offline Offline
Newbie Poster

Re: include files

 
0
  #2
May 28th, 2009
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.
Last edited by coppercup; May 28th, 2009 at 10:39 am.
Thanks! Fritz Green
Pedants of the world unite!
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 10
Reputation: toddsmith is an unknown quantity at this point 
Solved Threads: 0
toddsmith toddsmith is offline Offline
Newbie Poster

Re: include files

 
0
  #3
May 28th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 10
Reputation: toddsmith is an unknown quantity at this point 
Solved Threads: 0
toddsmith toddsmith is offline Offline
Newbie Poster

Re: include files

 
0
  #4
May 28th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 40
Reputation: beeerlover is an unknown quantity at this point 
Solved Threads: 6
beeerlover's Avatar
beeerlover beeerlover is offline Offline
Light Poster

Re: include files

 
0
  #5
May 28th, 2009
If you add this line to your .htaccess file:
AddType application/x-httpd-php .html .html pages will be able to execute .php commands.
www.beeerlover.org <- my hobby with 15K+ Pink Floyd Images
www.bestbridalprices.com <- my job with 15K+ Wedding Dresses
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,371
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 166
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso

Re: include files

 
0
  #6
May 28th, 2009
Originally Posted by beeerlover View Post
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
Failure is not an option It's included free, you don't have to do anything to get it
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 10
Reputation: toddsmith is an unknown quantity at this point 
Solved Threads: 0
toddsmith toddsmith is offline Offline
Newbie Poster

Re: include files

 
0
  #7
May 29th, 2009
Originally Posted by almostbob View Post
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
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 6
Reputation: coppercup is an unknown quantity at this point 
Solved Threads: 1
coppercup's Avatar
coppercup coppercup is offline Offline
Newbie Poster

Re: include files

 
0
  #8
May 29th, 2009
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!
Last edited by coppercup; May 29th, 2009 at 2:13 pm.
Thanks! Fritz Green
Pedants of the world unite!
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 10
Reputation: toddsmith is an unknown quantity at this point 
Solved Threads: 0
toddsmith toddsmith is offline Offline
Newbie Poster

Re: include files

 
0
  #9
May 29th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,371
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 166
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso

Re: include files

 
0
  #10
May 29th, 2009
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.
Failure is not an option It's included free, you don't have to do anything to get it
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC