Cannot parse php inside html - php

I've been beating myself up trying to get my php parse inside my html. I have used the following in my .htaccess to no avail.
AddType application/x-httpd-php .html - a dialog box pops up asking me to open a php file
AddType application/x-httpd-php5 .html - Same
AddHandler application/x-httpd-php .html - Same
AddHandler php-script .html - just doesnt parse but looking into the source code you can see the php
AddHandler php5-script .html - Same
I would like to point out as well that a normal .php file runs fine on the server.
What gives?

You have to change your server configuration. Go into your httpd.conf or .htaccess and change this line (or something close to it):
addtype application/x-httpd-php .php
to parse .html files like this:
addtype application/x-httpd-php .php .html
and then restart the server

Nevermind, figured it out. It has something to do with my doctype. short_open_tag is enabled so php is trying to parse because it thinks its php.
Solution:
Need to print that particular line with proper php syntax
<?php echo "<?xml version=\"1.0\" encoding=\"UTF-8\"; ?> ?>

Related

How to Parse HTML as PHP?

I'm using Apache2 on Heroku and I'm trying to parse HTML as PHP so I can include files inside a HTML file and use HTML as normal, so I don't have to copy paste the navigator and stuff, such as footer in each other html file. This makes work much easier.
I've tried to look things up, made .htaccess and httpd.conf work, but whatever I have done so far it doesn't really work. What it does at the moment is it gives me .html to download.
These are the current settings I have:
AddHandler x-httpd-php .html .htm
AddType application/x-httpd-php .html .htm
I AddType started to cause the .html to download.
Inside httpd.conf I have this:
AddHandler application/x-httpd-php .htm .html
<Files />
AddType application/x-httpd-php .html
</Files>
Update:
I've asked Heroku support, however, they don't support these things... uhm..
So, I've figured out that the buildpacks that Heroku has, this one: https://github.com/heroku/heroku-buildpack-php
has a folder inside support that includes this:
https://github.com/heroku/heroku-buildpack-php/tree/master/support/build/_conf/apache2
a httpd.conf that I can't access, because apperantly it builds from that. However I can remove that buildpack and replace it with mine. The problem is the buildpacks work like that
they have a bin folder with a compiler inside, and when I fork it, it still compiles it from their repository.
I need someone to help me out and fork it and basically modify it so that it doesn't load a httpd.conf at all, so that I can include mine and do stuff with it.
Update:
I am just using PHP now, since I can't do anything to change it, it's on heroku's side or the buildpack from heroku.
Your AddType seems to be ok:
AddType application/x-httpd-php .html .htm
Sometimes you need to indicate the PHP version:
AddType application/x-httpd-php5 .html .htm
or for PHP 7:
AddType application/x-httpd-php7 .html .htm
another solution is to remove html handler:
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
one more solution:
<FilesMatch "\.html$">
ForceType application/x-httpd-php
</FilesMatch>
Do not forget to restart the server to see the results!

Parsing php in html isn't working anymore

The parsing of my php pages in my html always worked well. But not anymore.
I am not sure when it stopped working.
I used this in my .htaccess file:
AddHandler x-httpd-php5 .php .htm .html
But that doesn't work anymore.
I googled and found other codes like with Addtype etc. but I can't get it to work.
Any ideas anyone?
This is one of the pages:
http://www.tina-turner.nl/dvd-vhs-others.htm
Johanna
The correct directive is :
AddHandler application/x-httpd-php5 .php .htm .html

Adding php code to .html file

I want to add php code to my .html file. I have searched a lot and din't find why it is not working
Steps i have followed for this:
1) Created a .htaccess file inside my htdocs
2) And added the following things
AddType text/html .shtml .shtm .htm .html
AddHandler application/x-httpd-php5.6 .html
3) Restarted my Apache.
Executed my page. My page contains
<?php
echo "hello";
?>
I din't see any errors and hello too. And i changed the htaccess content to
AddType application/x-httpd-php .htm .html
as mentioned here
It is also not working. I don't know whether htaccess file must contain some other elements or not. Please let me know.
Thanks
You need to set AllowOverride to All in httpd.conf, or in your virtual hosts file (httpd-vhosts.conf) if you are using them.
Otherwise, directives in your .htaccess file will not be allowed.
More information can be found here: http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride
Update
If it is set to All, then you should be able to do either of the following.
Unset the handler and reset it:
RemoveHandler .html .htm
AddType application/x-httpd-php .html .htm
Or, use FilesMatch:
<FilesMatch "\.(htm|html|php)$">
SetHandler application/x-httpd-php
</FilesMatch>
Try this :
AddHandler application/x-httpd-php .html

WAMP PHP/Apache selectively refusing to parse php pages

I have many years experience of working with Apache/PHP/MySQL directly and have only just started using WAMP.
I installed WAMP last week and had my first 4 PHP/MySQL websites up and running immediately. How much easier is this I began to think! That is until I added a fifth site and cannot get php to parse any php file below the websites root directory.
I have a test.php file containing just the word 'hello', ho HTML tags and no PHP directives.
If I place this into /wamp/www/ob/test.php it works, if I place it into /wamp/www/ob/html/test.php the browser comes up with 'You have chosen to open test.php, what should Firefox do with this file? Basically php failed to parse it.
My other sites are working fine with identical setup and this site plus three others were downloaded using Filezilla.
Can anybody help please before I uninstall WAMP and go back to installing Apache/MySQL/PHP manually.
Either the php handler is not turned on for that directory, or the content-type of the returned data is set wrong.
My WampDeveloper Pro setup has this...
<Directory "C:/WampDeveloper/Websites/*/webroot">
AddType text/html .php .php4 .php5 .phps
AddHandler application/x-httpd-php .php .php4 .php5
AddHandler application/x-httpd-php-source .phps
</Directory>
This turns on PHP for all website folders.
Has a DefaultType text/html in httpd.conf for fallback.
Also check any .htaccess files, they might be setting content-type to something other than 'text/html'.
The pages on the Internet that explain how to make Apache parse the PHP that you add to a file with the extension HTML suggest this:
AddType application/x-httpd-php .html .php .htm
AddHandler application/x-httpd-php .html .php .htm
If your Apache server is configured for php5 but not php, then the result, I believe, is the refusal described. I changed what I added to .htaccess to this (notice the digit 5):
AddType application/x-httpd-php5 .html .php .htm
AddHandler application/x-httpd-php5 .html .php .htm
That fixed the problem for me.

html w/php powered pages not displaying; downloadable?

When I try to load a php inside an html page, somepage.html ... It brings up a download box.
AddHandler application/x-httpd-php .html
AddType application/x-httpd-php html
Those were generated in my cpanel but still it shows a download box instead of the code.
What do I do?
Also additional information:
Apache version 2.2.17
PHP version 5.3.4
Not sure, but you can try:
AddType application/x-httpd-php .php .htm .html
AddHandler x-httpd-php .php .htm .html
Took it from this blog post.
EDIT: Just saw that you're using PHP inside .html files. Can't you just change the extension?

Categories