39 lines
970 B
PHP
39 lines
970 B
PHP
|
<?php
|
|||
|
/**
|
|||
|
* Here is your custom functions.
|
|||
|
*/
|
|||
|
|
|||
|
/**
|
|||
|
* Is Url In Domain With Path
|
|||
|
* @param $urlToCheck
|
|||
|
* @param $baseUrl
|
|||
|
* @return bool
|
|||
|
*/
|
|||
|
function isUrlInDomainWithPath($urlToCheck,$baseUrl): bool
|
|||
|
{
|
|||
|
|
|||
|
// 解析基础 URL
|
|||
|
$baseUrlParts = parse_url($baseUrl);
|
|||
|
if (!$baseUrlParts) {
|
|||
|
return false; // 解析失败
|
|||
|
}
|
|||
|
|
|||
|
$basePath = $baseUrlParts['path'] ?? '';
|
|||
|
|
|||
|
// 去除路径末尾的斜杠(如果有的话)
|
|||
|
$basePath = rtrim($basePath, '/');
|
|||
|
|
|||
|
// 解析要检查的 URL(只提取主机名)
|
|||
|
$urlToCheckParts = parse_url($urlToCheck);
|
|||
|
if (!$urlToCheckParts) {
|
|||
|
return false; // 解析失败
|
|||
|
}
|
|||
|
|
|||
|
$checkHost = $urlToCheckParts['host'] ?? '';
|
|||
|
|
|||
|
// 比较主机名是否相同,并且检查路径是否包含要检查的 URL 的主机名(这里其实是检查整个路径)
|
|||
|
if ($basePath === $checkHost && strpos($urlToCheck,$basePath) !== false) {
|
|||
|
return true;
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|