REQUEST_URI在使用开关盒时不打印var

时间:2016-09-04 15:11:49

标签: php

我正在尝试检查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;
}

1 个答案:

答案 0 :(得分:0)

我不得不改变

 $url = $_SERVER['REQUEST_URI'];
$domain = parse_url($url, PHP_URL_HOST); 

url = $_SERVER['SERVER_NAME'];
$domain = parse_url($url, PHP_URL_PATH);