WordPress at a glance
function is not described

Requests_Cookie::domain_matches() public WP 1.0

Check if a cookie is valid for a given domain

{} It's a method of the class: Requests_Cookie{}

No Hooks.


true|false. Whether the cookie is valid for the given domain


$Requests_Cookie = new Requests_Cookie();
$Requests_Cookie->domain_matches( $string );
$string(string) (required)
Domain to check

Code of Requests_Cookie::domain_matches() WP 5.7.2

public function domain_matches($string) {
	if (!isset($this->attributes['domain'])) {
		// Cookies created manually; cookies created by Requests will set
		// the domain to the requested domain
		return true;

	$domain_string = $this->attributes['domain'];
	if ($domain_string === $string) {
		// The domain string and the string are identical.
		return true;

	// If the cookie is marked as host-only and we don't have an exact
	// match, reject the cookie
	if ($this->flags['host-only'] === true) {
		return false;

	if (strlen($string) <= strlen($domain_string)) {
		// For obvious reasons, the string cannot be a suffix if the domain
		// is shorter than the domain string
		return false;

	if (substr($string, -1 * strlen($domain_string)) !== $domain_string) {
		// The domain string should be a suffix of the string.
		return false;

	$prefix = substr($string, 0, strlen($string) - strlen($domain_string));
	if (substr($prefix, -1) !== '.') {
		// The last character of the string that is not included in the
		// domain string should be a %x2E (".") character.
		return false;

	// The string should be a host name (i.e., not an IP address).
	return !preg_match('#^(.+\.)\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $string);