<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.session.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'function.session-id.php',
    1 => 'session_id',
    2 => '获取/设置当前会话 ID',
  ),
  'up' => 
  array (
    0 => 'ref.session.php',
    1 => 'Session 函数',
  ),
  'prev' => 
  array (
    0 => 'function.session-get-cookie-params.php',
    1 => 'session_get_cookie_params',
  ),
  'next' => 
  array (
    0 => 'function.session-module-name.php',
    1 => 'session_module_name',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/session/functions/session-id.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.session-id" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">session_id</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">session_id</span> &mdash; <span class="dc-title">获取/设置当前会话 ID</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.session-id-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>session_id</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$id</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>): <span class="type"><span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>session_id()</strong></span> 可以用来获取/设置
   当前会话 ID。
  </p>
  <p class="para">
   为了能够将会话 ID 很方便的附加到 URL 之后，
   你可以使用常量 <strong><code><a href="session.constants.php#constant.sid">SID</a></code></strong>
   获取以字符串格式表达的会话名称和 ID。
   请参考 <a href="ref.session.php" class="link">会话处理</a>。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.session-id-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">id</code></dt>
      <dd>
       <p class="para">
        如果指定了 <code class="parameter">id</code> 且不为 <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>，
        则使用指定值作为会话 ID。
        必须在调用 <span class="function"><a href="function.session-start.php" class="function">session_start()</a></span> 函数之前调用 
        <span class="function"><strong>session_id()</strong></span> 函数。
        不同的会话处理程序对于会话 ID 中可以使用的字符有不同的限制。
        例如文件会话处理程序仅允许会话 ID 中使用以下字符：<code class="literal">[a-zA-Z0-9,-]</code>
       </p>
       <blockquote class="note"><p><strong class="note">注意</strong>: 
        <span class="simpara">
         如果使用 cookie 方式传送会话 ID，并且指定了 <code class="parameter">id</code> 参数，
         在调用 <span class="function"><a href="function.session-start.php" class="function">session_start()</a></span> 
         之后都会向客户端发送新的 cookie，
         无论当前的会话 ID 和新指定的会话 ID 是否相同。
        </span>
       </p></blockquote>
      </dd>
     
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.session-id-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   <span class="function"><strong>session_id()</strong></span> 返回当前会话ID。
   如果当前没有会话，则返回空字符串（<code class="literal">&quot;&quot;</code>）。失败时返回 <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>。
  </p>
 </div>


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

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">id</code> 现在可以为 null。
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 seealso" id="refsect1-function.session-id-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.session-regenerate-id.php" class="function" rel="rdfs-seeAlso">session_regenerate_id()</a> - 使用新生成的会话 ID 更新现有会话 ID</span></li>
    <li><span class="function"><a href="function.session-start.php" class="function" rel="rdfs-seeAlso">session_start()</a> - 启动新会话或者重用现有会话</span></li>
    <li><span class="function"><a href="function.session-set-save-handler.php" class="function" rel="rdfs-seeAlso">session_set_save_handler()</a> - 设置用户自定义会话存储函数</span></li>
    <li>
     <a href="session.configuration.php#ini.session.save-handler" class="link">session.save_handler</a>
    </li>
   </ul>
  </p>
 </div>

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