N98\Magento\Command\System\Check\Settings\CookieDomainCheckAbstract::validateCookieDomainAgainstUrl PHP Метод

validateCookieDomainAgainstUrl() публичный Метод

it follows the following (incomplete) verification: - the site-domain is extracted from the base-url - site-domain and cookie-domain are normalized by making them lowercase - if the site-domain is empty, the check returns false because it's moot - if the cookie-domain is smaller than three, the check returns false because it's moot - if the cookie-domain does not start with a dot ("."), and the whole matches site-domain return true. - otherwise the dot is removed and the cookie-domain is now with removed starting dot. - the cookie domain must be the suffix of the site-domain and the remaining prefix of site-domain must end with a dot. returns true/false
public validateCookieDomainAgainstUrl ( string $cookieDomain, string $siteUrl ) : boolean
$cookieDomain string
$siteUrl string
Результат boolean
    public function validateCookieDomainAgainstUrl($cookieDomain, $siteUrl)
    {
        $siteDomain = strtolower(parse_url($siteUrl, PHP_URL_HOST));
        $siteLen = strlen($siteDomain);
        if (0 === $siteLen) {
            return false;
        }
        $cookieDomain = strtolower($cookieDomain);
        $cookieLen = strlen($cookieDomain);
        if (3 > $cookieLen) {
            return false;
        }
        $hasLeadingDot = $cookieDomain[0] === '.';
        if ($hasLeadingDot) {
            $cookieDomain = substr($cookieDomain, 1);
            $cookieLen = strlen($cookieDomain);
        } elseif ($siteDomain === $cookieDomain) {
            return true;
        }
        // cookie domain must at least contain a SLD.TLD, no match or match at offset 0 for '.' invalidates
        if (!strpos($cookieDomain, '.')) {
            return false;
        }
        $suffix = substr($siteDomain, -$cookieLen);
        if ($suffix !== $cookieDomain) {
            return false;
        }
        $prefix = substr($siteDomain, 0, -$cookieLen);
        if (0 === strlen($prefix)) {
            return false;
        }
        if (substr($prefix, -1) !== '.') {
            return false;
        }
        return true;
    }