<?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-set-cookie-params.php',
    1 => 'session_set_cookie_params',
    2 => '设置会话 cookie 参数',
  ),
  'up' => 
  array (
    0 => 'ref.session.php',
    1 => 'Session 函数',
  ),
  'prev' => 
  array (
    0 => 'function.session-save-path.php',
    1 => 'session_save_path',
  ),
  'next' => 
  array (
    0 => 'function.session-set-save-handler.php',
    1 => 'session_set_save_handler',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/session/functions/session-set-cookie-params.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.session-set-cookie-params" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">session_set_cookie_params</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">session_set_cookie_params</span> &mdash; <span class="dc-title">设置会话 cookie 参数</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.session-set-cookie-params-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>session_set_cookie_params</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$lifetime_or_options</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<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">$path</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<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">$domain</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<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.boolean.php" class="type bool">bool</a></span></span> <code class="parameter">$secure</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<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.boolean.php" class="type bool">bool</a></span></span> <code class="parameter">$httponly</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span><br>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">自 PHP 7.3.0 起可用的替代签名：</p>
  <div class="methodsynopsis dc-description"><span class="methodname"><strong>session_set_cookie_params</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$lifetime_or_options</code></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   Cookie 参数可以在 <var class="filename">php.ini</var> 文件中定义，本函数仅在当前脚本执行过程中有效。
   因此，如果要通过函数修改 cookie 参数，需要对每个请求都要
   在调用 <span class="function"><a href="function.session-start.php" class="function">session_start()</a></span> 函数之前调用
   <span class="function"><strong>session_set_cookie_params()</strong></span> 函数。
  </p>
  <p class="para">
   本函数会修改运行期 ini 设置值，
   可以通过 <span class="function"><a href="function.ini-get.php" class="function">ini_get()</a></span> 函数获取这些值。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.session-set-cookie-params-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">lifetime_or_options</code></dt>
     <dd>
      <p class="para">
       使用第一个签名时，session cookie 的 <a href="session.configuration.php#ini.session.cookie-lifetime" class="link">lifetime</a>，以秒为单位。
      </p>
      <p class="para">
       当使用第二个签名时，关联 <span class="type"><a href="language.types.array.php" class="type array">array</a></span> 可能具有 <code class="literal">lifetime</code>、<code class="literal">path</code>、<code class="literal">domain</code>、<code class="literal">secure</code>、<code class="literal">httponly</code>
       和 <code class="literal">samesite</code> 中的任一 key。这些值与同名参数的含义相同。<code class="literal">samesite</code> 元素的值应该是 <code class="literal">Lax</code> 或
       <code class="literal">Strict</code>。
       如果可以接受的键在传入的数组中不存在，那么会采用这些键对应的默认值作为运行时的值。如果省略 <code class="literal">samesite</code> 元素，则不会设置 SameSite cookie 属性。
      </p>
     </dd>
    
    
     <dt><code class="parameter">path</code></dt>
     <dd>
      <p class="para">
       此 cookie 的有效 <a href="session.configuration.php#ini.session.cookie-path" class="link">路径</a>。 on the domain where
       设置为“/”表示对于本域上所有的路径此 cookie 都可用。
      </p>
     </dd>
    
    
     <dt><code class="parameter">domain</code></dt>
     <dd>
      <p class="para">
       Cookie 的作用 <a href="session.configuration.php#ini.session.cookie-domain" class="link">域</a>。
       例如：“www.php.net”。
       如果要让 cookie 在所有的子域中都可用，此参数必须以点（.）开头，例如：“.php.net”。
      </p>
     </dd>
    
    
     <dt><code class="parameter">secure</code></dt>
     <dd>
      <p class="para">
       设置为 <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> 表示 cookie 仅在使用
       <a href="session.configuration.php#ini.session.cookie-secure" class="link">安全</a> 链接时可用。
      </p>
     </dd>
    
    
     <dt><code class="parameter">httponly</code></dt>
     <dd>
      <p class="para">
       设置为 <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> 表示 PHP 发送 cookie 的时候会使用
       <a href="session.configuration.php#ini.session.cookie-httponly" class="link">httponly</a>
       标记。
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.session-set-cookie-params-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.session-set-cookie-params-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>8.0.0</td>
       <td>
        <code class="parameter">path</code>、<code class="parameter">domain</code>、<code class="parameter">secure</code>
        和 <code class="parameter">httponly</code> 现在可为 null。
       </td>
      </tr>

      <tr>
       <td>7.3.0</td>
       <td>
        新增支持 <code class="parameter">lifetime_or_options</code> 数组的替代签名。此签名还支持 SameSite cookie 属性的设置。
       </td>
      </tr>

      <tr>
       <td>7.2.0</td>
       <td>
        成功时返回 <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>。以前该函数返回 <span class="type"><span class="type"><a href="language.types.void.php" class="type void">void</a></span></span>。
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.session-set-cookie-params-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li>
     <a href="session.configuration.php#ini.session.cookie-lifetime" class="link">session.cookie_lifetime</a>
    </li>
    <li>
     <a href="session.configuration.php#ini.session.cookie-path" class="link">session.cookie_path</a>
    </li>
    <li>
     <a href="session.configuration.php#ini.session.cookie-domain" class="link">session.cookie_domain</a>
    </li>
    <li>
     <a href="session.configuration.php#ini.session.cookie-secure" class="link">session.cookie_secure</a>
    </li>
    <li>
     <a href="session.configuration.php#ini.session.cookie-httponly" class="link">session.cookie_httponly</a>
    </li>
    <li>
     <a href="session.configuration.php#ini.session.cookie-samesite" class="link">session.cookie_samesite</a>
    </li>
    <li><span class="function"><a href="function.session-get-cookie-params.php" class="function" rel="rdfs-seeAlso">session_get_cookie_params()</a> - 获取会话 cookie 参数</span></li>
   </ul>
  </p>
 </div>


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