<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.outcontrol.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'function.output-add-rewrite-var.php',
    1 => 'output_add_rewrite_var',
    2 => '添加 URL 重写器的值',
  ),
  'up' => 
  array (
    0 => 'ref.outcontrol.php',
    1 => '输出控制 函数',
  ),
  'prev' => 
  array (
    0 => 'function.ob-start.php',
    1 => 'ob_start',
  ),
  'next' => 
  array (
    0 => 'function.output-reset-rewrite-vars.php',
    1 => 'output_reset_rewrite_vars',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/outcontrol/functions/output-add-rewrite-var.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.output-add-rewrite-var" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">output_add_rewrite_var</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">output_add_rewrite_var</span> &mdash; <span class="dc-title">添加 URL 重写器的值</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.output-add-rewrite-var-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>output_add_rewrite_var</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$name</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$value</code></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   如果“URL-Rewriter”输出缓冲处理程序未激活，此函数将启动它，存储 <code class="parameter">name</code> 和 <code class="parameter">value</code>
   参数，并在缓冲区刷新时根据有效的 ini 设置重写 <abbr title="Uniform Resource Locator">URL</abbr> 和表单。此函数后续的调用将存储所有附加的名/值对，直到处理程序关闭。
  </p>
  <p class="para">
   当冲刷输出缓冲区（调用 <span class="function"><a href="function.ob-flush.php" class="function">ob_flush()</a></span>、<span class="function"><a href="function.ob-end-flush.php" class="function">ob_end_flush()</a></span>、<span class="function"><a href="function.ob-get-flush.php" class="function">ob_get_flush()</a></span>
   或在脚本结束时）时，<code class="literal">&#039;URL-Rewriter&#039;</code> 处理程序会将名/值对作为查询参数添加到 HTML 标签属性的 <abbr title="Uniform Resource Locator">URL</abbr>
   中，并根据 <a href="outcontrol.configuration.php#ini.url-rewriter.tags" class="link">url_rewriter.tags</a> 和
   <a href="outcontrol.configuration.php#ini.url-rewriter.hosts" class="link">url_rewriter.hosts</a> 配置指令的值向表单添加隐藏字段。
  </p>
  <p class="para">
   添加到 <code class="literal">&#039;URL-Rewriter&#039;</code> 处理程序的每个名/值对都会添加到 <abbr title="Uniform Resource Locator">URL</abbr> 或表单，即使这会导致重复的
   <abbr title="Uniform Resource Locator">URL</abbr> 查询参数或具有相同名称属性的元素。
  </p>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <span class="simpara">
    一旦关闭了 <code class="literal">&#039;URL-Rewriter&#039;</code> 处理程序，就无法再次启动。
   </span>
  </p></blockquote>
  <div class="warning"><strong class="warning">警告</strong>
   <p class="simpara">
    在 PHP 8.4.0 之前，要重写的主机设置在 <a href="session.configuration.php#ini.session.trans-sid-hosts" class="link">session.trans_sid_hosts</a>
    中，而不是 <a href="outcontrol.configuration.php#ini.url-rewriter.hosts" class="link">url_rewriter.hosts</a> 中。
   </p>
  </div>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.output-add-rewrite-var-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">name</code></dt>
     <dd>
      <p class="para">
       变量名。
      </p>
     </dd>
    
    
     <dt><code class="parameter">value</code></dt>
     <dd>
      <p class="para">
       变量值。
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.output-add-rewrite-var-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>， 或者在失败时返回 <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.output-add-rewrite-var-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>7.1.0</td>
       <td>
        自 PHP 7.1.0 起，使用专用的输出缓冲区，<a href="outcontrol.configuration.php#ini.url-rewriter.tags" class="link">
        url_rewriter.tags</a> 仅用于输出函数，并且 <a href="outcontrol.configuration.php#ini.url-rewriter.tags" class="link">url_rewriter.hosts</a> 可用。在 PHP 7.1.0
        之前，由 <span class="function"><strong>output_add_rewrite_var()</strong></span> 设置的重写变量共享具有透明
        session id 支持的输出缓冲区（请参阅 <a href="session.configuration.php#ini.session.trans-sid-tags" class="link">session.trans_sid_tags</a>）。
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.output-add-rewrite-var-examples">
  <h3 class="title">示例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>示例 #1 <span class="function"><strong>output_add_rewrite_var()</strong></span> 示例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />ini_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'url_rewriter.tags'</span><span style="color: #007700">, </span><span style="color: #DD0000">'a=href,form='</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">output_add_rewrite_var</span><span style="color: #007700">(</span><span style="color: #DD0000">'var'</span><span style="color: #007700">, </span><span style="color: #DD0000">'value'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// 一些链接<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">'&lt;a href="file.php"&gt;link&lt;/a&gt;<br />&lt;a href="http://example.com"&gt;link2&lt;/a&gt;'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// 表单<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">'&lt;form action="script.php" method="post"&gt;<br />&lt;input type="text" name="var2" /&gt;<br />&lt;/form&gt;'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">ob_list_handlers</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>以上示例会输出：</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">&lt;a href=&quot;file.php?var=value&quot;&gt;link&lt;/a&gt;
&lt;a href=&quot;http://example.com&quot;&gt;link2&lt;/a&gt;

&lt;form action=&quot;script.php&quot; method=&quot;post&quot;&gt;
&lt;input type=&quot;hidden&quot; name=&quot;var&quot; value=&quot;value&quot; /&gt;
&lt;input type=&quot;text&quot; name=&quot;var2&quot; /&gt;
&lt;/form&gt;

Array
(
    [0] =&gt; URL-Rewriter
)</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.output-add-rewrite-var-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.output-reset-rewrite-vars.php" class="function" rel="rdfs-seeAlso">output_reset_rewrite_vars()</a> - 重设 URL 重写器的值</span></li>
    <li><span class="function"><a href="function.ob-flush.php" class="function" rel="rdfs-seeAlso">ob_flush()</a> - 冲刷（发送）活动输出处理程序的返回值</span></li>
    <li><span class="function"><a href="function.ob-list-handlers.php" class="function" rel="rdfs-seeAlso">ob_list_handlers()</a> - 列出所有使用的输出处理程序</span></li>
    <li><a href="outcontrol.configuration.php#ini.url-rewriter.tags" class="link">url_rewriter.tags</a></li>
    <li><a href="outcontrol.configuration.php#ini.url-rewriter.hosts" class="link">url_rewriter.hosts</a></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>