Htm和HTML页面中的PHP代码

时间:2017-03-07 23:22:56

标签: php html apache .htaccess cpanel

我的index.html文件

<html> 
    <head>
        <title> PHP inside HTML </title>
    </head>
    <body>
        <h1>
            <?php
                  echo "PHP Output";
            ?>
        </h1>
        <h1>
            <p>
                HTML Output
            </p>
        </h1>
    </body>
</html>

我的上述代码的预期输出:

PHP输出
HTML输出

我尝试了以下组合但这些都没有帮助我获得输出。

AddHandler application/x-httpd-php56 .shtml .html .htm
AddHandler server-parsed .shtml .shtm .htm .html
AddHandler x-httpd-php .html .htm
AddHandler application/x-httpd-php5 .html .htm

第二组代码不起作用

AddHandler application/x-httpd-php .htm
AddHandler application/x-httpd-php .html
AddType application/x-httpd-php .htm
AddType application/x-httpd-php .html

第3套代码无效。

AddHandler x-httpd-php5 .html
AddHandler x-httpd-php5 .htm
AddHandler application/x-httpd-php .htm
AddHandler application/x-httpd-php .html

使用.htaccess添加Mime类型。

AddType application/x-httpd-php .htm
AddType application/x-httpd-php .html

导致下载文件而不是工作。

返回内部服务器错误

Options +ExecCGIenter
AddHandler fcgid-script .html
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html

请帮我解决此问题。

我已经在堆栈溢出中引用了页面,但所有代码都不适用于我。 StackOverFlow

1 个答案:

答案 0 :(得分:0)

如果您的帐户位于基于Cloudlinux的服务器下,请使用以下代码,希望它能正常使用。

代码

AddHandler application/x-httpd-ea-php56 .htm .html .shtml

AddType application/x-httpd-php5 .php

考虑PHP版本并相应地修改代码。