是否可以隐藏源代码中用PHP编写的代码

时间:2014-07-25 04:25:18

标签: php

下面是我的代码,我在PHP中编写代码并在正文中调用它。当我运行它并查看源代码时,代码变得可见。我看到一些网站没有在源上显示任何内容,但网页上显示一个表单。我怎么能这样做?

<?php
{   $avatar_form  = '<form id="avatar_form" enctype="multipart/form-data" method="post" action="myphoto.php">';
    $avatar_form .=   '<h4>Change your avatar</h4>';
    $avatar_form .=   '<input type="file" name="avatar" required>';
    $avatar_form .=   '<p><input type="submit" value="Upload"></p>';
    $avatar_form .= '</form>';
}


?>
<!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>Avatar</title>
</head>

<body>
<div><?php echo $avatar_form; ?></div>
</body>
</html>

由于 Shail

2 个答案:

答案 0 :(得分:1)

为什么不用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>Avatar</title>
</head>

<body>
<div>
<form id="avatar_form" enctype="multipart/form-data" method="post" action="myphoto.php">
<h4>Change your avatar</h4>
<input type="file" name="avatar" required>
<p><input type="submit" value="Upload"></p>
</form>
</div>
</body>
</html>

使用php来回显html有时不会更快或更有用,然后直接在.html文件中编写。

答案 1 :(得分:0)

This is Output of the code, And this is the page source showing at my side my browser.. 检查文件类型是.php还是.html? 如果是html,它将显示php代码。 如果是这样,请将其另存为.php

相关问题