/** * Extracts just the domain part that determines a cookie's host validity. * * @param string $host Host name to truncate. * * @return string Domain or false on a bad host. */ protected function truncateHost($host) { $tlds = SimpleUrl::getAllTopLevelDomains(); if (preg_match('/[a-z\\-]+\\.(' . $tlds . ')$/i', $host, $matches)) { return $matches[0]; } elseif (preg_match('/[a-z\\-]+\\.[a-z\\-]+\\.[a-z\\-]+$/i', $host, $matches)) { return $matches[0]; } return false; }
function _chompHost(&$url) { if (preg_match('/^(\\/\\/)(.*?)(\\/.*|\\?.*|#.*|$)/', $url, $matches)) { $url = $matches[3]; return $matches[2]; } if (preg_match('/(.*?)(\\.\\.\\/|\\.\\/|\\/|\\?|#|$)(.*)/', $url, $matches)) { $tlds = SimpleUrl::getAllTopLevelDomains(); if (preg_match('/[a-z0-9\\-]+\\.(' . $tlds . ')/i', $matches[1])) { $url = $matches[2] . $matches[3]; return $matches[1]; } elseif (preg_match('/[a-z0-9\\-]+\\.[a-z0-9\\-]+\\.[a-z0-9\\-]+/i', $matches[1])) { $url = $matches[2] . $matches[3]; return $matches[1]; } } return false; }