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

Breadcrumb

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

function SetCookie::matchesPath

Check if the cookie matches a path value.

A request-path path-matches a given cookie-path if at least one of the following conditions holds:

  • The cookie-path and the request-path are identical.
  • The cookie-path is a prefix of the request-path, and the last character of the cookie-path is %x2F ("/").
  • The cookie-path is a prefix of the request-path, and the first character of the request-path that is not included in the cookie- path is a %x2F ("/") character.

Parameters

string $requestPath Path to check against:

File

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

Class

SetCookie
Set-Cookie object

Namespace

GuzzleHttp\Cookie

Code

public function matchesPath(string $requestPath) : bool {
    $cookiePath = $this->getPath();
    // Match on exact matches or when path is the default empty "/"
    if ($cookiePath === '/' || $cookiePath == $requestPath) {
        return true;
    }
    // Ensure that the cookie-path is a prefix of the request path.
    if (0 !== \strpos($requestPath, $cookiePath)) {
        return false;
    }
    // Match if the last character of the cookie-path is "/"
    if (\substr($cookiePath, -1, 1) === '/') {
        return true;
    }
    // Match if the first character not included in cookie path is "/"
    return \substr($requestPath, \strlen($cookiePath), 1) === '/';
}

API Navigation

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