PHP - session_get_cookie_params() Function
Definition and Usage
Sessions or session handling is a way to make the data available across various pages of a web application. The session_get_cookie_params() is used to retrieve the session cookie parameters.
Syntax
session_get_cookie_params([$array]);
Parameters
This method doesnt accept any parameters.
Return Values
This function returns an array which contains the current session cookie parameter values.
PHP Version
This function was first introduced in PHP Version 4 and works in all the later versions.
Example 1
Following example demonstrates the usage of the session_get_cookie_params() function.
<html>
<head>
<title>Setting up a PHP session</title>
</head>
<body>
<?php
//Setting the cookie parameters
session_set_cookie_params(30 * 60, "/", "test", );
//Retrieving the cookie parameters
$res = session_get_cookie_params();
//Starting the session
session_start();
print_r($res);
?>
</body>
</html>
One executing the above html file it will display the following message −
Array ( [lifetime] => 1800 [path] => /test [domain] => test.com [secure] => [httponly] => [samesite] => )
Example 2
This is another example of this function.
<html>
<head>
<title>Setting up a PHP session</title>
</head>
<body>
<?php
//Retrieving the cookie parameters
$currentCookieParams = session_get_cookie_params();
//Setting the cookie parameters
$domain = '.test.com';
session_get_cookie_params(
$currentCookieParams["lifetime"],
$currentCookieParams["path"],
$domain,
$currentCookieParams["secure"],
$currentCookieParams["httponly"]
);
//Starting the session
session_start();
?>
</body>
</html>
php_function_reference.htm
Advertisements