www.webdeveloper.com
Results 1 to 11 of 11

Thread: trying to create html pages with a php include-is it possible?

  1. #1
    Join Date
    Oct 2011
    Posts
    12

    trying to create html pages with a php include-is it possible?

    Is it possible to create an .html page using a php include without saving it as an .php page? I'm assuming it's probably in an .htaccess file, but I have no idea on how to do it. Any help is appreciated! I built a site using Dreamweaver, but I hate DW, and want to go back to doing it myself with notepad. I hope I explained this okay.

    This is what I have on the html page:

    <?php include 'includes/menu.php'; ?>

    I have created a folder called includes, and my menu in it is saved as menu.php

    Thanks!

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    727
    I don't have an answer to your file naming question, but I suggest you NOT use a plain text editor to write your php/html code. Get something that respects the syntax of the languages you are using and highlights the appropriate words and function names and helps you detect errors in your typing. Notepad just won't do that. DW may have done it and if so, you see how much you miss it very quickly I think.

  3. #3
    Join Date
    Oct 2013
    Posts
    486

  4. #4
    Join Date
    Feb 2012
    Posts
    17
    Quote Originally Posted by Kevin2 View Post
    Thanks Kevin, but this does nothing, I've already got the htaccess set up that way. It seems that the only way to do this is to just name the pages with a .php instead of html. I've several variations, and nothing works.

  5. #5
    Join Date
    Feb 2012
    Posts
    17
    Thanks for the reply, but I don't want to use DW. I do not miss it at all, and consider it Adobe's mistake. It's a skiddish program that won't promise the same results twice, therefore, it is unusable-for me anyway. If anybody else likes it, they can have it.

  6. #6
    Join Date
    Oct 2013
    Posts
    486
    Is your menu.php file set up correctly?

    Wrong:
    Code:
    <?php
    <a href="/index.htm">Home</a> - 
    <a href="/about.htm">About Us</a> - 
    <a href="/products.htm">Products</a>
    ?>
    Correct:
    Code:
    <a href="/index.htm">Home</a> - 
    <a href="/about.htm">About Us</a> - 
    <a href="/products.htm">Products</a>
    Alternatively, if your host/server allows SSI you could use the second example (i.e. HTML only), rename your PHP file to menu.txt, then drop the following in your HTML pages where you want it:
    Code:
    <!--#include virtual="/includes/menu.txt"-->
    To keep your same HTML file extensions this goes in your .htaccess file:
    Code:
    Options +Includes
    AddType text/html .shtml
    AddOutputFilter INCLUDES .htm	# change to .html if needed

  7. #7
    Join Date
    Feb 2012
    Posts
    17
    Quote Originally Posted by Kevin2 View Post
    Is your menu.php file set up correctly?

    Wrong:
    Code:
    <?php
    <a href="/index.htm">Home</a> - 
    <a href="/about.htm">About Us</a> - 
    <a href="/products.htm">Products</a>
    ?>
    Correct:
    Code:
    <a href="/index.htm">Home</a> - 
    <a href="/about.htm">About Us</a> - 
    <a href="/products.htm">Products</a>
    Alternatively, if your host/server allows SSI you could use the second example (i.e. HTML only), rename your PHP file to menu.txt, then drop the following in your HTML pages where you want it:
    Code:
    <!--#include virtual="/includes/menu.txt"-->
    To keep your same HTML file extensions this goes in your .htaccess file:
    Code:
    Options +Includes
    AddType text/html .shtml
    AddOutputFilter INCLUDES .htm	# change to .html if needed

    Thanks so much for your reply Kevin. I tried this one:

    <!--#include virtual="/includes/menu.txt"-->

    It still doesn't work.

    My menu.php starts like this:

    <ul class="menu" id="menu" style="list-style-type:none;">
    <ul>
    <li><a href="http://www.welcometothe70s.com"><strong>Home</strong></a></li>

    I have this in my htaccess:

    # AddType application/x-httpd-php .html .php .htm


    # To allow execution of cgi scripts in this directory uncomment next two lines.


    # AddHandler x-httpd-php5-cgi .html
    # Options +ExecCGI +FollowSymLinks
    # Options +Includes
    # AddType text/html .shtml
    # AddOutputFilter INCLUDES .htm # change to .html if needed

    I did an SSI test, and it seems to work. In my includes folder I have the menu saved in .php, .html, and .txt
    I'd really like to figure this out because I don't want to save these pages as .php

    Thanks again!

  8. #8
    Join Date
    Oct 2013
    Posts
    486
    FYI, a hash (#) in front of a line in .htaccess turns that line into a comment. In other words it's not executed. So
    # AddType application/x-httpd-php .html .php .htm

    Should be
    AddType application/x-httpd-php .html .php .htm

  9. #9
    Join Date
    Feb 2012
    Posts
    17
    Quote Originally Posted by Kevin2 View Post
    FYI, a hash (#) in front of a line in .htaccess turns that line into a comment. In other words it's not executed. So
    # AddType application/x-httpd-php .html .php .htm

    Should be
    AddType application/x-httpd-php .html .php .htm
    I tried this, and it only downloads pages to my desktop. In Chrome it automatically downloads the file. In Firefox, it asks me how I want to download it. This is a tough one.

  10. #10
    Join Date
    Oct 2013
    Posts
    486
    Actually, I think the .htaccess line should be
    AddType application/x-httpd-php .html .htm

    Notice I removed .php from the AddType extensions.

  11. #11
    Join Date
    Feb 2012
    Posts
    17
    Quote Originally Posted by Kevin2 View Post
    Actually, I think the .htaccess line should be
    AddType application/x-httpd-php .html .htm

    Notice I removed .php from the AddType extensions.
    No, it's just not working. Do you know of a sample htaccess page? Maybe I'm doing something wrong there.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles