Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. SetCookie.php

function SetCookie::matchesDomain

Check if the cookie matches a domain value.

Parameters

string $domain Domain to check against:

File

vendor/guzzlehttp/guzzle/src/Cookie/SetCookie.php, line 415

Class

SetCookie
Set-Cookie object

Namespace

GuzzleHttp\Cookie

Code

public function matchesDomain(string $domain) : bool {
    $cookieDomain = $this->getDomain();
    if (null === $cookieDomain) {
        return true;
    }
    // Remove the leading '.' as per spec in RFC 6265.
    // https://datatracker.ietf.org/doc/html/rfc6265#section-5.2.3
    $cookieDomain = \ltrim(\strtolower($cookieDomain), '.');
    $domain = \strtolower($domain);
    // Domain not set or exact match.
    if ('' === $cookieDomain || $domain === $cookieDomain) {
        return true;
    }
    // Matching the subdomain according to RFC 6265.
    // https://datatracker.ietf.org/doc/html/rfc6265#section-5.1.3
    if (\filter_var($domain, \FILTER_VALIDATE_IP)) {
        return false;
    }
    return (bool) \preg_match('/\\.' . \preg_quote($cookieDomain, '/') . '$/', $domain);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal