/    Sign up×
Community /Pin to ProfileBookmark

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!

to post a comment
PHP

12 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmFeb 10.2014 — 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.
Copy linkTweet thisAlerts:
@lycialiveFeb 11.2014 — Here's one way:

http://php.about.com/od/advancedphp/p/html_php.htm[/QUOTE]
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.
Copy linkTweet thisAlerts:
@lycialiveFeb 11.2014 — 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.
Copy linkTweet thisAlerts:
@Kevin2Feb 11.2014 — 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>
?>[/CODE]


Correct:
[CODE]<a href="/index.htm">Home</a> -
<a href="/about.htm">About Us</a> -
<a href="/products.htm">Products</a>[/CODE]


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"-->[/CODE]

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[/CODE]
Copy linkTweet thisAlerts:
@lycialiveFeb 11.2014 — 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>
?>[/CODE]


Correct:
[CODE]<a href="/index.htm">Home</a> -
<a href="/about.htm">About Us</a> -
<a href="/products.htm">Products</a>[/CODE]


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"-->[/CODE]

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[/CODE]
[/QUOTE]



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!
Copy linkTweet thisAlerts:
@Kevin2Feb 11.2014 — 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
Copy linkTweet thisAlerts:
@lycialiveFeb 11.2014 — 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[/QUOTE]


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.
Copy linkTweet thisAlerts:
@Kevin2Feb 11.2014 — Actually, I think the .htaccess line should be

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

Notice I removed .php from the AddType extensions.
Copy linkTweet thisAlerts:
@lycialiveFeb 11.2014 — Actually, I think the .htaccess line should be

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

Notice I removed .php from the AddType extensions.[/QUOTE]


No, it's just not working. Do you know of a sample htaccess page? Maybe I'm doing something wrong there.
Copy linkTweet thisAlerts:
@Douglas_WilliamFeb 12.2018 — ... does not have to [I]post[/I] ... Cute ... it is an *.html file originally and the php [I]include[/I] will not function as the extension remains html. Server-side recognition for execution.

...just couldn't resist -

Hope this helps me out ...

Doug
Copy linkTweet thisAlerts:
@rootFeb 13.2018 — Please don't resurrect old posts, this one is a few days over 4 years old.

If you have a question you want answering, please ask a question by starting your own thread.

Thanks.
×

Success!

Help @darklite spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...