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\CookieCode
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);
}