travel/service/app/functions.php

39 lines
970 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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;
}