PHP » Cookies and Sessions » session_set_cookie_params()

Syntax:
void session_set_cookie_params(int lifetime [, string path [, string domain [, bool secure]]])
lifetime
Sets a time when the cookie will be deleted from the browser. If it is omitted, the cookie will disappear when the browser is closed. The lifetime is specified as a number of seconds.
path
Specifies a web site document path in which the cookie will be sent. Outside this path the cookie is not valid. If left out, it will be set to the path of the document creating the cookie.
domain
The domain that the cookie is valid in. The default value is the server that created the cookie. If the site spans several servers that need to access the cookie, their common domain needs to be chosen. The domain cannot be a top domain and not a domain that the server creating the cookie does not belong to.
secure
Whether the cookie must be retrieved in a secure setting (SSL). Default is FALSE.

Sets the parameters for the session cookie.

This function sets the cookie parameters for the session cookies. These parameters can also be set in the configuration file php.ini.

Examples

Code:
<?php

session_set_cookie_params(30 * 60, "/");
session_start();
print_r(session_get_cookie_params());

?>
Output:
Array ( [lifetime] => 1800 [path] => / [domain] => [secure] => )
Explanation:

Sets the cookie to expire after 30 minutes and be available anywhere on the site.

See Also: