$authorized_domains = arrayexamplecom subdomainexamplecom; 授权的域名列表$current_domain = $_SERVERHTTP_HOST; 获取当前域名if !in_array$current_domain $authorized_domains echo 未授权; exit;如何把域名列表写成获取远程地址
要获取远程地址作为域名列表,可以使用以下代码:
$remote_url = 'https://example.com/remote_domains.php'; // 远程地址
$remote_domains = file_get_contents($remote_url); // 获取远程地址内容
if ($remote_domains === false) {
echo '无法获取远程地址';
exit;
}
$authorized_domains = explode("\n", $remote_domains); // 将远程地址内容按行分割为域名列表
$current_domain = $_SERVER['HTTP_HOST']; // 获取当前域名
if (!in_array($current_domain, $authorized_domains)) {
echo '未授权';
exit;
}
在上面的代码中,$remote_url 是远程地址,file_get_contents() 函数用于获取远程地址的内容。然后,使用 explode() 函数将远程地址的内容按行分割为域名列表。最后,再根据当前域名判断是否在授权的域名列表中。如果不在列表中,则输出 "未授权" 并退出程序
原文地址: http://www.cveoy.top/t/topic/hESv 著作权归作者所有。请勿转载和采集!