• 首页
  • vue
  • TypeScript
  • JavaScript
  • scss
  • css3
  • html5
  • php
  • MySQL
  • redis
  • jQuery
  • session_get_cookie_params()

    (PHP 4, PHP 5, PHP 7)

    获取会话 cookie 参数

    说明

    session_get_cookie_params(void): array

    获取会话 cookie 的参数。

    返回值

    返回一个包含当前会话 cookie 信息的数组:

    • "lifetime"- cookie 的生命周期,以秒为单位。
    • "path"- cookie 的访问路径。
    • "domain"- cookie 的域。
    • "secure"-仅在使用安全连接时发送 cookie。
    • "httponly"-只能通过 http 协议访问cookie

    更新日志

    版本说明
    5.2.0在返回数组中加入“httponly”。
    4.0.4在返回数组中加入“secure”。

    参见

    • session.cookie_lifetime
    • session.cookie_path
    • session.cookie_domain
    • session.cookie_secure
    • session.cookie_httponly
    • session_set_cookie_params() 设置会话 cookie 参数
    It should be noted that this gets the session cookie ini file parameters, not the parameters from the cookie itself.
    ie. if you set the cookie lifetime using session_set_cookie_params(12345) and then try to use session_get_cookie_params, you will not get back 12345. Instead, you will get the lifetime set in the ini file.
    This function is quite handy when it comes to expiring session cookies... since Session cookies don't automatically get destroyed (see the session_destroy page).
    For instance, here's what I plan to use to expire session cookies:
      $CookieInfo = session_get_cookie_params();
      if ( (empty($CookieInfo['domain'])) && (empty($CookieInfo['secure'])) ) {
        setcookie(session_name(), '', time() 3600, $CookieInfo['path']);
      } elseif (empty($CookieInfo['secure'])) {
        setcookie(session_name(), '', time() 3600, $CookieInfo['path'], $CookieInfo['domain']);
      } else {
        setcookie(session_name(), '', time() 3600, $CookieInfo['path'], $CookieInfo['domain'], $CookieInfo['secure']);
      }
      session_destroy();
    It doesn't check to see if the path part of the session cookie is set because the defaults in php.ini have this set already, unlike domain and secure.
    Try also
    * INI_Get('session.cookie_lifetime')
    * INI_Get('session.cookie_path')
    * INI_Get('session.cookie_domain')
    * INI_Get('session.cookie_secure')
    * INI_Get('session.cookie_httponly')
    separately instead of session_Get_Cookie_Params().
    Additionally there is a "bug" - session.cookie_lifetime is mentioned twice in the description.

    上篇:session_gc()

    下篇:session_id()