Current Location: Home> Function Categories> session_set_cookie_params

session_set_cookie_params

Set session cookie parameters
Name:session_set_cookie_params
Category:Session Session
Programming Language:php
One-line Description:Set the parameters of the session cookie

Function name: session_set_cookie_params()

Applicable version: PHP 4 >= 4.0.4, PHP 5, PHP 7

Function description: session_set_cookie_params() function is used to set the parameters of the session cookie.

Syntax: session_set_cookie_params($lifetime, $path, $domain, $secure, $httponly)

parameter:

  • $lifetime: Optional parameter, specifying the life cycle of the session cookie, in seconds. The default value is 0, indicating that the session cookie expires when the browser closes.
  • $path: Optional parameter, specifying the valid path to the session cookie. The default value is the root directory (/).
  • $domain: optional parameter, specifying the valid domain name of the session cookie. The default value is empty, indicating the current domain name.
  • $secure: Optional parameter that specifies whether the session cookie is transmitted only over a secure HTTPS connection. The default value is false.
  • $httponly: Optional parameter that specifies whether the session cookie is accessed only through the HTTP protocol. The default value is false.

Return value: This function does not return value.

Example:

 // 设置会话cookie 的生命周期为1 小时session_set_cookie_params(3600); // 设置会话cookie 的有效路径为/myapp/ session_set_cookie_params(0, '/myapp/'); // 设置会话cookie 的有效域名为example.com session_set_cookie_params(0, '/', 'example.com'); // 设置会话cookie 仅通过安全的HTTPS 连接传输session_set_cookie_params(0, '/', '', true); // 设置会话cookie 仅通过HTTP 协议访问,并且在1 小时后过期session_set_cookie_params(3600, '/', '', false, true);

The above example demonstrates different usages of the session_set_cookie_params() function. The life cycle, valid path, valid domain name, transmission method and other parameters of the session cookie can be set according to specific needs. Please select the appropriate parameter value according to the actual situation.

Similar Functions
Popular Articles