function drupal_setcookie

Drupal's wrapper around PHP's setcookie() function.

This allows the cookie's $value and $options to be altered.

Parameters

$name: The name of the cookie.

$value: The value of the cookie.

$options: An associative array which may have any of the keys expires, path, domain, secure, httponly, samesite.

See also

setcookie()

Related topics

4 calls to drupal_setcookie()
drupal_session_commit in includes/session.inc
Commits the current session, if necessary.
drupal_session_regenerate in includes/session.inc
Called when an anonymous user becomes authenticated or vice-versa.
toolbar_toggle_page in modules/toolbar/toolbar.module
Menu callback; toggles the visibility of the toolbar drawer.
_drupal_session_delete_cookie in includes/session.inc
Deletes the session cookie.

File

includes/bootstrap.inc, line 3964

Code

function drupal_setcookie($name, $value, $options) {
    $options = _drupal_cookie_params($options);
    if (\PHP_VERSION_ID >= 70300) {
        setcookie($name, $value, $options);
    }
    else {
        $defaults = array(
            'expires' => 0,
            'path' => '',
            'domain' => '',
            'secure' => FALSE,
            'httponly' => FALSE,
        );
        $options += $defaults;
        setcookie($name, $value, $options['expires'], $options['path'], $options['domain'], $options['secure'], $options['httponly']);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.