简体   繁体   中英

Lighttpd escapes <?php ?> in served html files?

I'm working on a lighttpd server in an embedded system that is not configured by me. I use Google Chrome to see the source code for the HTML files. I don't know what's wrong but when I request the following simple file:

Note: the file extension is.html

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
Hello world!
<?php echo "PHP commands"?>
</body>
</html>

It gives the following file to my browser:

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
Hello world!
<!--?php echo "PHP commands"?-->
</body>
</html>

In other words it comments out the php commands disabling them? Why? How can I solve it. Couldn't find anything wrong in the config files.

Even though it is not saved in a file with.php extension, I want lighttpd to ignore the php commands inside the html. I know it's not a valid HTML, but I want it to be untouched.

My guess is that:

  1. The embedded system does not have a working PHP interpreter or is not configured for the file extension you are using.

  2. You are inspecting the HTML code through a browser tool (Firebug or something) that's not showing the original HTML but the generated HTML. Since <?php... ?> is not a valid HTML tag, it's converted to a (valid) comment.

This is a pain, and I found that only "fix" is to give your files an extension of .php , which many people aren't keen to do..

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