You are here

public function SetCookie::matchesPath in Auth0 Single Sign On 8.2

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:

Return value

bool

File

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

Class

SetCookie
Set-Cookie object

Namespace

GuzzleHttp\Cookie

Code

public function matchesPath($requestPath) {
  $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) === '/';
}