简体   繁体   中英

Can't run php code from inside html file

I am having a problem running my php code from inside an html file. I have tried the .htaccess method and the handler method. I'm using a webserver with cpanel(version 11), apache(2.2.15) and php(5.2.13).I have also tried the files on xampp and they work perfect, but when I upload them to the webserver the php code from inside the html will not run. Any suggestions, please?

You need to inform Apache that files of type 'html' need to be parsed by PHP. You can do this by adding this to the Apache configuration file (httpd.conf):

AddType application/x-httpd-php .html

However if you have other HTML files I would advise just rename the file to PHP (or set up some internal mapping so you don't specify an extension all together). If you have static HTML files that you serve, it's redundant to have them being executed by the PHP interpreter.

为什么不将其制成PHP文件,然后用.htaccess HTML重写PHP扩展名?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM