php will not run in my .htm page? - php

index.htm I have 6 lines of PHP code that wont run on my page I don't get an error of any kind it just wont run if you look in source it shows my raw PHP. I have a file named test.php that works fine. in test.php I only have those 6 lines of code that you can see in my index.htm
Server Name defiro
cPanel Version 11.36.2 (build 9)
Theme x3
Apache version 2.2.24
PHP version 5.2.17
MySQL version 5.5.30-30.2
Architecture x86_64
Operating system linux
i have tryed to fix the problem by putting AddType application/x-httpd-php .html in my websites .htaccess file as listed in PHP not working on HTML file i have tryed a few other things by trying to get an error out of the php with no luck
Edit__
it wont let me use php or html in a file together no matter if it is .html or .php it wont work i don't know how to fix it?

Let me see
index.htm I have 6 lines of PHP code that wont run on my page I don't get an error of any kind it just wont run if you look in source it shows my raw PHP. I have a file named test.php that works fine. in test.php I only have those 6 lines of code that you can see in my index.htm
Let me make some assumptions
index.htm has php tags inside (<?php echo 'if this works'; ?>) that do not parse when you make your request. The tags don't even show up in your browser.
test.php is a file that starts and ends with php tags (<?php /*php content*/ ?>). It runs as expected. (mind you, you can add content before or after php tags and it will be displayed raw).
If these assumptions are not correct please say so in a comment
Some other assumptions
you set up your own server or you haven't fiddled with the configuration yet
my suggestion
Go to your httpd.conf apache configuration file
Look for something that resembles the following
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
The one that's talking about php is the line you're interested in, it determines which file extensions will be parsed by the php interpreter before being sent to the client. OK, change it to look like this
AddType application/x-httpd-php .php .html .htm
You can add as many space-separated extensions you want, but be warned, sometimes you want a raw file, so be carefull
SAVE and RESTART the server. Important, everytime you change the conf
Please give feedback if this does not help you

you have put the following in
AddType application/x-httpd-php .html
That targets .html files, You need to target .htm files so changing to
AddType application/x-httpd-php .htm
should fix it

Related

htacces file & PHP parsing issue

There is a problem with PHP parsing the html files on my site.
I've been using php in html files, together with the directive
AddHandler application/x-httpd-php5 .html .htm
in the .htaccess file, without any problem for 5 years.
Since a couple of days ago, suddenly it doesn't work anymore.
Only the .php files are parsed properly and the html files are not, anymore
(the actual php code is displayed instead of the result of the execution!)
I contacted the host service but they say they can't offer support.
I thought that for some reason the .htaccess file is not read anymore by the server,
but I tested it with a redirect directive and it worked.
Then I thought that they modified something in the php engine and beside the above mentioned directive I've tried each of the following directives:
AddHandler application/x-httpd-php .html .htm
AddType application/x-httpd-php5 .html .htm
AddType application/x-httpd-php .html .htm
AddHandler x-mapp-php5 .html .htm
but no success.
So html file are not php parsed anymore, but I've noticed someting interesting about the index.html file:
if I access mydomain.com/index.html the result is bad,
HOWEVER, if I access just mydomain.com then it displays properly !!
(And of course, there is no index.php file). That means the index.html file is actually parsed, in this case.
BUT, the situation stays the same even if the .htaccess file is deleted.
For this particular file (index.html), the behavior is the same in any of the subdirectories.
As the hosting service is not helpful with checking their server configuration settings,
I wonder if there is anything I can try on my side, as I'm stuck with this.
And any hints would be welcome.
Thanks.

what code do i put in .htacess to use php?

Just wanted to know what code I have to put in my .htaccess file so my html pages read php that im going to put in there, (just a contact form), I did find it once but can't remember, sorry and thanks.
You have to convert your html files to php
put this line in your .htaccess if you're using apache2
AddType application/x-httpd-php .html .htm
but make sure that your .htaccess file is in the root directory of the website
If you want PHP in HTML files to be interpreted just add this line to your .htaccess file:
AddType application/x-httpd-php .html .htm
HTML Pages don't read your PHP. Instead Apache is reading your file and executes it with a PHP interpreter if some PHP is in there.
Just in case you have a debian server with apache2 you can apt-get install php5. But there is a lot more work to do, for example FCGI and so on.

php files are downloaded instead of ran

My problem started when I was working with the .htaccess file to a directory trying to get php to run inside of html files. I tried ALOT of combinations of AddTypes and AddHandlers. I took them out and now my php files are being downloaded by the broswer instead of running. There are a few other questions on here that I have studied up and down, but they are not exactly my problem.
I'm fairly lost now, I've tried just about every combination of AddType and AddHandler. I've since decided to use mod_rewrite and just have all my files end in .php but I can't get them to run.
This is what I'm using to test:
<!DOCTYPE html>
<body>
<?php
echo("php working");
?>
</body>
</html>
Am I missing something? Luckily I made all my changes at a separate directory than the root so that the site still runs, but none of the php files in that folder can be viewed in broswer. What can I do? Any help is appreciated.
EDIT:
Just to make it clear, I was originally trying to be able to put php in my html files so I was messing around with handlers and addtypes. My server does have php. If I call a php script from a .html file, it runs. I just can't get a php file like the example I included above to open in brower ANYMORE, it used to open in browser. My fear is that I have messed something up by trying all the different handlers in .htaccess. I have since cleared my .htaccess file in hopes that would at least get me to square one, but it hasn't.
SECOND EDIT:
I went to the root directory and made a php file and it ran just fine so its definitely something I changed in the .htaccess for the particular directory. Is there anyway I can reset that directory?
have you made sure to install php correctly within apache?
if you are using php as a module, you need the following:
LoadModule php5_module "c:/php/php5apache2.dll"
AddType application/x-httpd-php .php
# configure the path to php.ini
PHPIniDir "C:/php"
or as a CGI binary
ScriptAlias /php/ "c:/php/"
AddType application/x-httpd-php .php
# For PHP 4
Action application/x-httpd-php "/php/php.exe"
# For PHP 5
Action application/x-httpd-php "/php/php-cgi.exe"
other things to consider, are the permissions set correctly on the php binaries, is the php.ini present and correct, have you restarted apache since installing php into apache?
lastly, php doesnt run within html files, you would need to set the following as pretty much the last thing in the apache config
AddType application/x-httpd-php .html .htm
Do you see the line like this in your htaccess file?
php_flag engine off
If yes, delete it.
One more thing that may help you understand what happened
The following piece of htaccess would make Php from being executed but rather downloaded as a text file
<VirtualHost *>
ServerName sourcecode.testserver.me
DocumentRoot /var/www/example
AddType text/plain php
</VirtualHost>
One more thing
I'm guessing that this topic was addressed once here-> htaccess downloading file instead of loading

HTML through PHP parser

I'm trying to hide the fact I'm using PHP on one of my site pages and I'm wanting to run it through the PHP parser (just that page not them all) so I can call it filename.html as usual. I have tried a few Apache directives I found online and have a few in my .htaccess file (hotlinks and for a 404 page).
When i use one of the scripts (in my .htacess) for the PHP purpose, the page wants to be saved/downloaded (like a vcard does) and a box shows - with no page to view. Can anyone please help. I'm new to PHP but believe a module might be needed or that it could be to do with the config of my server.
You should leave the page with a .php extension and have Apache handle the file as a normal PHP file. Then use a RewriteRule in your htaccess settings to hide the php file as follows:
RewriteEngine on
RewriteRule ^yourfile\.html$ yourfile.php
There is no real need to hide the fact that you are using PHP, but if you really want to parse PHP in html files you need to edit your Apache httpd.conf file. Open it up in a text editor and find a group of lines that looks like this:-
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
(Yours may be slightly different)
Then add
AddType text/html .html
restart Apache and php in html files will be parsed.

How Do I enable PHP to be shown on HTML webpage?

I have been searching on forums and google for hours with no definitive answer other than "Your host may not support PHP". I have dumbed down my PHP page to simply display some text for testing purposes but I am still only getting a blank webpage. I have tried opening it locally into a browser and also through the web server, same result for both. Anyone have an idea as to why this simple PHP wont even show up on the webpage?
<?php
echo "Show some text";
?>
also tried:
<html>
<?php
echo "Show some text";
?>
</html>
What is the filename of your file? Is the file extension a .html file, or a .php file? If it's .html, rename it to .php and test with your first test again.;
To check and see if php is supported on your server, create another file titled: phpinfo.php and insert the following code in it:
<?php
phpinfo();
?>
and save it, and then go to it on your server. You should see the PHP configuration output on that page. If it doesn't work, then you do not have PHP correctly installed on your server.
Your file must be ending in .phtml or .php to make PHP work on a HTML page.
index.php
<?php
echo "Hello World!";
?>
Or you can trick your server, Apache and Nginx support this as does IIS. Basically you can have "index.x" or "index.px" - your own custom extension, it is not advisable for obvious reasons. In Apache (your public_html folder) enable this in your .htaccess file:
AddType application/x-httpd-php .php
AddType application/x-httpd-php .ac1d
AddType application/x-httpd-php .php4
AddType application/x-httpd-php .phtml
AddType application/x-httpd-php .x
# your custom extension above.
To view the source of everything (no processing):
Most server are setup with a source-viewing format already by changing the file name to use the .phps extension. If not, you'd have to create a .htaccess file and temporarily add this line to it:
AddType text/plain .php
AddType text/plain .html
That should force the files to be displayed as plain text whenever they're accessed. Just remember to remove it later.

Categories