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:
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).