You are here

public static function secureCookieBasic::set in Secure Cookie Data 7.2

Setter for the class.

Parameters

array|object $data: The data to be stored in the cookie.

Return value

boolean TRUE if the cookie was modified/set, FALSE if not.

2 calls to secureCookieBasic::set()
secureCookieTreeTwo::set_tree in modules/secure_cookie_data_tree_two.class.inc
Setter for the class.
secure_cookie_data_put in ./secure_cookie_data.module
Sets the secure cookie with the given data.

File

./secure_cookie_data.class.inc, line 131
secure_cookie.class.inc @author António P. P. Almeida <appa@perusio.net> @date Wed Dec 21 03:17:53 2011

Class

secureCookieBasic

Code

public static function set($data) {

  // Decode the given data.
  $cookie_data = (object) $data;

  // Compute the HMAC right away.
  $cookie_data->hmac = secureCookieBasic::set_hmac(json_encode($cookie_data));

  // Encode the data.
  $encoded_data = secureCookieBasic::encode($cookie_data);

  // Set the cookie.
  if (setcookie(static::$__cookie_name, $encoded_data, static::$__cookie_duration, static::$__cookie_path, secureCookieBasic::get_domain(), secureCookieBasic::secure_session_p(), TRUE)) {

    // Set the superglobal if the cookie setting was successful.
    $_COOKIE[static::$__cookie_name] = $encoded_data;
    return TRUE;
  }
  return FALSE;
}