You are here

function hook_authcache_cookie in Authenticated User Page Caching (Authcache) 7.2

Return information about cookies in use.

Modules and themes may declare the characteristics of cookies they use by implementing this hook. Doing so will allow authcache to manage those cookies, i.e. setting and deleting them when a user-session is started and terminated respectively.

Parameters

object $account: The user object on which the operation was just performed.

Return value

array An array of cookie items. Each cookie item has a key corresponding to the cookie-name. The corresponding array value is an associative array that may contain the following key-value pairs:

  • "present": TRUE if the cookie should be present in the users browser, FALSE otherwise. Defaults to FALSE.
  • "value": The cookies value. Defaults to NULL.
  • "lifetime": An integer value specifying how many seconds the cookie should be kept by the browser. Defaults to the PHP ini value session.cookie_lifetime.
  • "path": The path in which the cookie will be available on. Defaults to the PHP ini value session.cookie_path.
  • "domain": The domain that the cookie is available to. Defaults to the PHP ini value session.cookie_domain.
  • "secure": Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client. Defaults to the PHP in value session.cookie_secure.
  • "httponly": When TRUE the cookie will be made accessible only through the HTTP protocol. This means that the cookie won't be accessible by scripting languages, such as JavaScript. Defaults to FALSE.
  • "samesite": Either a string value (one of "Lax", "Strict", "None") or NULL (the default). Falls back to site wide default if omitted.

See also

authcache_fix_cookies()

setcookie()

4 functions implement hook_authcache_cookie()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

authcache_authcache_cookie in ./authcache.module
Implements hook_authcache_cookie().
authcache_p13n_authcache_cookie in modules/authcache_p13n/authcache_p13n.module
Implements hook_authcache_cookie().
authcache_test_authcache_cookie in tests/authcache_test.module
Implements hook_authcache_cookie().
authcache_usercookie_authcache_cookie in examples/authcache_usercookie/authcache_usercookie.module
Implements hook_authcache_cookie().
1 invocation of hook_authcache_cookie()
authcache_fix_cookies in ./authcache.module
Add and remove cookies to the browser session as required.

File

./authcache.api.php, line 198
Authcache API documentation.

Code

function hook_authcache_cookie($account) {
  $authenticated = $account->uid;
  $enabled = authcache_account_allows_caching();
  $present = $authenticated && $enabled;
  $cookies['aceuser']['present'] = $present;
  if ($present) {
    $cookies['aceuser']['value'] = $account->name;
  }
  return $cookies;
}