網頁

2013年3月18日 星期一

Enable PHP Inside HTML Pages


How to Enable PHP Inside HTML Pages



php code can be embedded within html pages within the tags:
<?php echo "my php code"; ?>

However, and depending on the server that you are using, this must be enabled. On apache2, you can edit the .htaccess file to include:
AddType application/x-httpd-php .htm .html

 added this line to the .htaccess on my website's root directory.

PHP coding in HTML file help (WAMP server)?

An HTML file still sits on the web server. You simply have to tell the web server how to parse the file. 

Your have to configure Apache server to parse the HTML files through the PHP engine. In httpd.conf, you probably have a line like this:

AddType application/x-httpd-php .php

This assumes you have the PHP module loaded (which you do). This way, it only parses PHP files.

You would have to change it to this:
AddType application/x-httpd-php .php .html .htm

Now apache will send all those file types to the PHP module for parsing.

Check the setup of Apache to fix this.


or 設定 httpd.conf  in conf/apache/httpd.conf 設定完記得重啓Server
AddType application/x-httpd-php .php .phtml .htm .html

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。