Hi, 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?
+1
A:
Why don't make it a PHP file and then rewrite PHP extension with HTML in .htaccess
?
Otar
2010-09-02 16:28:50
+2
A:
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.
Peter Kruithof
2010-09-02 16:30:02
The thing is I don't have acces to the httpd.conf file, just the .htacces file and Cpanel's Apache Handlers, where I could modify how apache handles certain files.I will probably have to make it a php file, because it kinda seems like a dead end.
Vidi
2010-09-02 16:37:29
If you have MultiViews enabled you can also ditch the extension and Apache will automagically pick up a PHP file with that name, eg:http://domain.tld/foowill have a foo.php file (in the document root) being parsed. More on MultiViews here: http://httpd.apache.org/docs/current/content-negotiation.html#multiviewsYou can enable MultiViews in your .htaccess file I think: Options +MultiViews
Peter Kruithof
2010-09-02 16:42:25
Yeah, i do.Thank you for your help.
Vidi
2010-09-02 17:00:34