Current Location: Home> Function Categories> session_get_cookie_params

session_get_cookie_params

Get session cookie parameters
Name:session_get_cookie_params
Category:Session Session
Programming Language:php
One-line Description:Get the cookie parameters for the current session

Function name: session_get_cookie_params()

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

Function description: The session_get_cookie_params() function is used to obtain the cookie parameters of the current session.

usage:

 $params = session_get_cookie_params();

Return value: This function returns an associative array containing the following four parameters:

  • lifetime: The validity period of a cookie (in seconds). If the value is 0, it means that the session cookie will be deleted when the browser is closed.
  • path: The valid path to the cookie. The default is the root directory "/".
  • domain: a valid domain name for a cookie. The default is an empty string, indicating the current domain name.
  • secure: A boolean value indicating whether the cookie is transmitted only over a secure HTTPS connection. Default is false.

Example:

 // 获取当前会话的cookie参数$params = session_get_cookie_params(); // 打印cookie参数echo "Lifetime: " . $params['lifetime'] . "<br>"; echo "Path: " . $params['path'] . "<br>"; echo "Domain: " . $params['domain'] . "<br>"; echo "Secure: " . ($params['secure'] ? 'true' : 'false') . "<br>";

Output example:

 Lifetime: 1440 Path: / Domain: Secure: false

In the above example, we first use the session_get_cookie_params() function to get the cookie parameter of the current session and store the returned associative array in the variable $params . Then, we use the echo statement to print out the values ​​of each cookie parameter. In this example, the lifetime is 1440 seconds (i.e. 24 minutes), the path is the root directory "/", the domain is an empty string (representing the current domain name), and the secure is false (representing transmission over a non-HTTPS connection).

Similar Functions
Popular Articles