我正在尝试检查URl
并为每个域及其路径加载一个不同的变量,例如example.com and example.com/dir
,但是当我运行echo $region
时,我什么也得不到。甚至试过echo $domain
,但我什么都没得到。
global $region;
$url = $_SERVER['REQUEST_URI']; // Get current url
$domain = parse_url($url, PHP_URL_HOST); // Get only path
preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs);
$domain = !empty($regs['domain']) ? $regs['domain'] : '';
echo $domain; <--- not printing
switch ($domain) {
case 'example.com':
$region = 'usa'; <--- not printing
break;
case 'two_example.com':
$region = 'pie'; <--- not printing
break;
default:
echo $domain; <--- not printing
break;
}
答案 0 :(得分:0)
我不得不改变
$url = $_SERVER['REQUEST_URI'];
$domain = parse_url($url, PHP_URL_HOST);
到
url = $_SERVER['SERVER_NAME'];
$domain = parse_url($url, PHP_URL_PATH);