/    Sign up×
Community /Pin to ProfileBookmark

can we write php in file.html

Dear all
+ I have a file.html contains a frame
+ Could I write php code in file.html? or only file.php
Thank you

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@pier_IPSep 27.2011 — Only in php file.

To add php code in an html file, you must change the file extension from "html" to "php".

Then you can insert php code so: [code=php]<?php /*php code*/ ?>[/code]
Copy linkTweet thisAlerts:
@eval_BadCode_Sep 27.2011 — You CAN, but i advise you strongly against it. Its asking for trouble plain and simple.

Here's how to do it anyways. Put this in your .htaccess file
[CODE]
<FilesMatch ".html$">
AddHandler x-httpd-php5.3 .html
</FilesMatch>
[/CODE]


There are other directives that will allow you to do it for only 1 file.
Copy linkTweet thisAlerts:
@TecBratSep 27.2011 — Also in .htaccess (Assumes Apache server, and that you have access to it) try this:[CODE]RewriteEngine On
RewriteRule ^file.html$ "file.php" [L][/CODE]
Copy linkTweet thisAlerts:
@TecBratSep 28.2011 — Also in .htaccess (Assumes Apache server, and that you have access to it) try this:[CODE]RewriteEngine On
RewriteRule ^file.html$ "file.php" [L][/CODE]
[/QUOTE]


After I posted this, I realized I didn't think it through all the way and that while this allows the URL to still contain "file.html" that your code still has to be in "file.php", but in many cases when a question like this comes up, that's good enough.
×

Success!

Help @chinhth2010 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.28,
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,
)...