Bitrix Site Manager

CMain::set

CMain::set_cookie(
 string name, 
 string value,
 mixed expire = false,
 string path = "/",
 mixed domain = false,
 bool secure = false,
 bool spread = true,
 mixed name_prefix = false
)

The method set sets the cookie and optionally stores its parameters to spread the cookie among sites of different domains.

Parameters

ParameterDescription
name Name of the cookie.
value Value of the cookie.
expire Date of the cookie expiration after which the cookie value is not transferred from the client to the site, in the Unix format.
Optional. By default, the cookie is declared valid within 1 year.
path Section (folder) of the site for which the cookie is effective.
Optional; by default the cookie is set for the whole site.
domain Domain for which the cookie is effective.
Optional. By default, the current site is used.
secure Specifies the secure cookie to be set. If true, the cookie value is transferred to the site if only a visitor has connected to the site via the HTTPS protocol.
Optional. The default value is false.
spread If set to true, the cookie parameters are stored for the subsequent spread among domains (administrative menu Sites, the field Domain name in the site settings).
name_prefix Prefix of the cookie name.
Optional. By default, the value of the parameter Cookie name prefix is used (this parameter is specified in the settings of the Kernel module). You can obtain the value of this parameter using the following call:
COption::GetOptionString("main", "cookie_name", "BITRIX_SM")

See Also

Example



<?
global $APPLICATION;
// set the cookie for 2 years, effective for the directory /en/
$APPLICATION->set_cookie("UK_VISITOR_ID", 
                         156, 
                         time()+60*60*24*30*12*2,
                         "/en/");
?>