<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/security.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'security.hiding.php',
    1 => '隐藏 PHP',
    2 => '隐藏 PHP',
  ),
  'up' => 
  array (
    0 => 'security.php',
    1 => '安全',
  ),
  'prev' => 
  array (
    0 => 'security.variables.php',
    1 => '用户提交的数据',
  ),
  'next' => 
  array (
    0 => 'security.current.php',
    1 => '保持更新',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'security/hiding.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="security.hiding" class="chapter">
   <h1 class="title">隐藏 PHP</h1>

   <p class="para">
    一般而言，通过隐藏来实现安全是最脆弱的安全方式之一。但在某些情况下，每一点额外的安全都是值得的。
   </p>
   <p class="para">
    一些简单的方法可以帮助隐藏 <abbr title="PHP: Hypertext Preprocessor">PHP</abbr>，这可能会减慢攻击者试图找到系统弱点的速度。
    通过在 <var class="filename">php.ini</var> 文件中设置 expose_php 为 <code class="literal">off</code>，
    可以减少能获得的有用信息。
   </p>
   <p class="para">
    另一个策略是配置 web 服务器（例如 apache）通过 <abbr title="PHP: Hypertext Preprocessor">PHP</abbr> 解析不同的文件类型，
    无论是通过 <var class="filename">.htaccess</var> 文件还是 apache 的配置文件，都可以设置能误导攻击者的文件扩展名：
    <div class="example" id="example-1">
     <p><strong>示例 #1 把 PHP 隐藏为另一种语言</strong></p>
     <div class="example-contents">
<div class="apache-confcode"><pre class="apache-confcode"># 使 PHP 代码看起来像其他代码类型
AddType application/x-httpd-php .asp .py .pl</pre>
</div>
     </div>

    </div>
    或者干脆彻底隐藏它：
    <div class="example" id="example-2">
     <p><strong>示例 #2 使用未知的扩展名作为 PHP 的扩展名</strong></p>
     <div class="example-contents">
<div class="apache-confcode"><pre class="apache-confcode"># 使 PHP 代码看起来像未知的类型
AddType application/x-httpd-php .bop .foo .133t</pre>
</div>
     </div>

    </div>
    或者隐藏它为 <abbr title="Hyper Text Markup Language">HTML</abbr> 代码，这样会有轻微的性能影响，因为所有的
    <abbr title="Hyper Text Markup Language">HTML</abbr> 都将通过 <abbr title="PHP: Hypertext Preprocessor">PHP</abbr> 引擎进行解析：
    <div class="example" id="example-3">
     <p><strong>示例 #3 使用 <abbr title="Hyper Text Markup Language">HTML</abbr> 作为 PHP 扩展名</strong></p>
     <div class="example-contents">
<div class="apache-confcode"><pre class="apache-confcode"># 使所有的 PHP 代码看起来像 HTML
AddType application/x-httpd-php .htm .html</pre>
</div>
     </div>

    </div>
    要让此方法生效，必须把 <abbr title="PHP: Hypertext Preprocessor">PHP</abbr>
    文件的扩展名改为以上的扩展名。这样就通过隐藏来提高了安全性，这是一个小的预防措施，几乎没有缺点。
   </p>
  </div>
<?php manual_footer($setup); ?>