You are here

function drupal_setcookie in Drupal 7

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

3 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.
_drupal_session_delete_cookie in includes/session.inc
Deletes the session cookie.

File

includes/bootstrap.inc, line 3896
Functions that need to be loaded on every Drupal request.

Code

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