Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
html中的php代码即使在启用addhandler in.htaccess后也无法工作_Php_Html_Apache_.htaccess - Fatal编程技术网

html中的php代码即使在启用addhandler in.htaccess后也无法工作

html中的php代码即使在启用addhandler in.htaccess后也无法工作,php,html,apache,.htaccess,Php,Html,Apache,.htaccess,我在html文件中有一小段php代码,但当我浏览到该文件时,它会显示部分代码,而不是执行。下面是代码 <?php session_start(); if (!$_SESSION["valid_user"]) { // User not logged in, redirect to login page Header('Location: login.html?returnurl=' . urlencode($_SERVER['REQUEST_URI'])); }

我在html文件中有一小段php代码,但当我浏览到该文件时,它会显示部分代码,而不是执行。下面是代码

<?php
session_start();
if (!$_SESSION["valid_user"])
  {
   // User not logged in, redirect to login page
    Header('Location: login.html?returnurl=' . urlencode($_SERVER['REQUEST_URI']));
   }
  echo "<p><a href=\"logout.html\">logout " . $_SESSION["valid_user"] . "</a></p>";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
php版本:5.4.4 服务器:apache


如果有人能帮助用以下命令替换
Addhandler
指令,这将非常有帮助:

AddHandler php5-script .php .html
在我的例子中(运行php5和apache的OS X Yosemite 10.10),当我使用任何AddHandler创建.htaccess时,apache会抛出500个错误配置错误

然而,我确实发现修改我的/etc/apache2/other/php5.conf非常有效

Before:  AddType application/x-httpd-php .php
After:   AddType application/x-httpd-php .php .html .htm
Before:  AddType application/x-httpd-php .php
After:   AddType application/x-httpd-php .php .html .htm