Matthew Cheung
asked on
PHP IN HTML Stopped Working on Server Side (Either Shows PHP Code or downloads the HTML File)
I have a website that used to work but ever since I suspect an upgrade from the provider it has stopped. This website is pretty simple, but I had inserted PHP to run inside HTML. It works when I run it on a local machine with XAMPP installed on. But when I add the similar settings to the website it either just shows the PHP code or as soon as I open the website it downloads the HTML page that I refer to.
All I have done on the website side is adjust the HTACCESS to include the below (have tried different ones and they either end up downloading the HTML or just displaying the PHP Code).
#AddType application/x-httpd-php .htm
#AddType application/x-httpd-php .html
#AddType text/html .html
#AddType application/x-httpd-php .php .html
#AddHandler x-httpd-php56 .php .html
AddHandler application/x-httpd-php .php .html .htm
With that simple insertion before on the website it worked, now it has stopped.
I checked what PHP version and it said 5.6,, when it works on XAMPP that is running 5.5.1.
Can anyone give me any guidance, checks or fixes.
Highly appreciated
Cheers
Matthew
All I have done on the website side is adjust the HTACCESS to include the below (have tried different ones and they either end up downloading the HTML or just displaying the PHP Code).
#AddType application/x-httpd-php .htm
#AddType application/x-httpd-php .html
#AddType text/html .html
#AddType application/x-httpd-php .php .html
#AddHandler x-httpd-php56 .php .html
AddHandler application/x-httpd-php .php .html .htm
With that simple insertion before on the website it worked, now it has stopped.
I checked what PHP version and it said 5.6,, when it works on XAMPP that is running 5.5.1.
Can anyone give me any guidance, checks or fixes.
Highly appreciated
Cheers
Matthew
are you using short tag in your php codes? if yes, try verify the short tag setting in php setting file and make sure it's turned on?
Seems like you're NOT in control over that website. Ask the helpdesk of that website provider if PHP is even installed, and if so, why the .htaccess is not being read (maybe you need to configure it somewhere else, a website from someone else DOESN'T HAVE TO listen to your .htaccess file, though if you're a big provider, it is appreciated).
And if it DOES listen to your .htaccess file AND has PHP installed, ask if that's the correct line to use (AddHandler application/x-httpd-php .php .html .htm). Maybe the server config is slightly different than what you'd expect.
And if it DOES listen to your .htaccess file AND has PHP installed, ask if that's the correct line to use (AddHandler application/x-httpd-php .php .html .htm). Maybe the server config is slightly different than what you'd expect.
I just moved a client from PHP-5.6 (non-FPM) to PHP-7.4.1 (FPM) who mistakenly injected PHP into 1000s of .html files (a very bad idea).
This takes a fair bit of hacking up of the FPM config to get this working.
If time is a factor + number of files is small, changing all the .html files to .php files will be must faster.
If you can tolerate the performance penalty of running PHP for every single static file on your site, have lots of time, lots of patience, and a good bit of command link Kung Fu, I can work through all the steps with you.
Before starting down this rabbit hole, first say if just changing .html file to .php files can easily be done.
This takes a fair bit of hacking up of the FPM config to get this working.
If time is a factor + number of files is small, changing all the .html files to .php files will be must faster.
If you can tolerate the performance penalty of running PHP for every single static file on your site, have lots of time, lots of patience, and a good bit of command link Kung Fu, I can work through all the steps with you.
Before starting down this rabbit hole, first say if just changing .html file to .php files can easily be done.
ASKER
Thanks for all the replies, just trying to digest as not a super expert on all this. My coding was pretty simply I think. I have this inserted into the HTML CODE
$sql="select * from tblabout";
$result=mysql_query($sql);
// place text onto page
while($row = mysql_fetch_array($result) )
{
echo "<p>" .$row['about_us'] . "</p>";
}
?>
When it runs on the server now (that worked before) I see .$row['about_us'] . appear. Not sure if that sheds anymore light into what might be happening on the server side now?
$sql="select * from tblabout";
$result=mysql_query($sql);
// place text onto page
while($row = mysql_fetch_array($result)
{
echo "<p>" .$row['about_us'] . "</p>";
}
?>
When it runs on the server now (that worked before) I see .$row['about_us'] . appear. Not sure if that sheds anymore light into what might be happening on the server side now?
ASKER
Hey Ryan,
I just got in my mailbox said you replied, but I cannot find anything in this topic?
I just got in my mailbox said you replied, but I cannot find anything in this topic?
Well, it's because I have deleted my own comment as after think twice, I thought that comment doesn't help to resolve your issue..
I run php in Windows with IIS but not with Apache HTTP server these days. so can't really comment much regarding HTACCESS settings.
but if I remember it correctly, it probably due to the short tag issue in the setting. And alternatively, check if you can run phpinfo and check that setting?
I run php in Windows with IIS but not with Apache HTTP server these days. so can't really comment much regarding HTACCESS settings.
but if I remember it correctly, it probably due to the short tag issue in the setting. And alternatively, check if you can run phpinfo and check that setting?
<?php phpinfo(); ?>
Try adding this to your .htaccess
I am guessing the provider dropped support for PHP5 and as a result your AddHandler is not working.
Also, if you have a CPanel check that your site is configured to run on the latest version.
Failing that get in touch with your provider and ask them what they changed. Usually, if they support PHP, you should not have to add anything to your .htaccess for php to run - so an option is to disable the addHandler directives and see if that works.
Bottom line I suspect a dropped support for PHP5 (they all doing it at the moment) and that is what is causing your problem.
AddHandler application/x-httpd-php70 .php
I am guessing the provider dropped support for PHP5 and as a result your AddHandler is not working.
Also, if you have a CPanel check that your site is configured to run on the latest version.
Failing that get in touch with your provider and ask them what they changed. Usually, if they support PHP, you should not have to add anything to your .htaccess for php to run - so an option is to disable the addHandler directives and see if that works.
Bottom line I suspect a dropped support for PHP5 (they all doing it at the moment) and that is what is causing your problem.
Code complexity has no bearing/effect/meaning regards your question.
The fix is somewhat complex + requires answering many questions, if a fix must be put in place.
As asked above, do you prefer simply changing .html file names to use the .php extension or do you prefer starting down the long path of hacking up your PHP config to run PHP .html files might contain.
Once you answer this question, will determine next steps.
The fix is somewhat complex + requires answering many questions, if a fix must be put in place.
As asked above, do you prefer simply changing .html file names to use the .php extension or do you prefer starting down the long path of hacking up your PHP config to run PHP .html files might contain.
Once you answer this question, will determine next steps.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.