Documentation

set_cookie

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

The method sets cookie and saves paramters of the set cookie if required to distribute among sites at different domain names. Non-static method.

Parameters

ParameterDescription Available from version
name Name of a cookie variable.
value Value of a cookie variable.
time Time and date in Unix format after which the cookie will be deemed as expired and its value will not be passed from a visitor to the site.
Optional parameter. By default - cookie is set for 1 year period.
folder Web site folder for which the cookie will be valid.
Optional parameter. By default - complete site.
domain Domain for which the cookie will be valid.
Optional parameter. By default - current site.
secure Flag ''secure'' for specified cookie. If true, it will be set as ''protected'', i. e. its value will be returned to the site only if the visitor has entered the web site via HTTPS protocol.
Optional. By default - "false".
spread If "true", the parameters of the specified cookie will be saved for further distribution on domains (admin menu "Sites", in site settings сайта - "Domain name").
name_prefix Prefix for the name of cookie variable.
Optional parameter. By default - value of the "Prefix for cookie" parameter in the main module settings (value of this parameter can be returned via the following method:
COption::GetOptionString("main", "cookie_name", "BITRIX_SM")
httpOnly Optional parameter. By default - "false".

See Also

Examples of use

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


© «Bitrix24», 2001-2022
Up