Skip to content

Commit

Permalink
Small refactor for how HTTP_BASE is generated. Removing non-obvious r…
Browse files Browse the repository at this point in the history
…egular expression. Fixes #1436
  • Loading branch information
markstory committed Jan 14, 2011
1 parent 459e2ef commit 7548379
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions cake/basics.php
Expand Up @@ -464,17 +464,21 @@ function env($key) {
break;
case 'HTTP_BASE':
$host = env('HTTP_HOST');
$count = substr_count($host, '.');
if ($count <= 1) {
$parts = explode('.', $host);
$count = count($parts);

if ($count === 1) {
return '.' . $host;
} elseif ($count === 2) {
return '.' . $host;
} elseif ($count === 3) {
$gTLD = array('aero', 'asia', 'biz', 'cat', 'com', 'coop', 'edu', 'gov', 'info', 'int', 'jobs', 'mil', 'mobi', 'museum', 'name', 'net', 'org', 'pro', 'tel', 'travel', 'xxx');
$domainName = explode('.', $host);
if (in_array($domainName[1], $gTLD)) {
$host = '.' . $host;
if (in_array($parts[1], $gTLD)) {
return '.' . $host;
}
}
return preg_replace('/^([^.])*/i', null, $host);
array_shift($parts);
return '.' . implode('.', $parts);
break;
}
return null;
Expand Down

0 comments on commit 7548379

Please sign in to comment.