mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Fixing env('HTTP_BASE') for site domain names that have the form
xxx.yyy.zzz and use second level TLDs.
This commit is contained in:
parent
4c3337598e
commit
8d15ba5037
2 changed files with 34 additions and 9 deletions
|
@ -446,7 +446,7 @@ if (!function_exists('array_combine')) {
|
||||||
if (defined('SERVER_IIS') && SERVER_IIS === true) {
|
if (defined('SERVER_IIS') && SERVER_IIS === true) {
|
||||||
return str_replace('\\\\', '\\', env('PATH_TRANSLATED'));
|
return str_replace('\\\\', '\\', env('PATH_TRANSLATED'));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'DOCUMENT_ROOT':
|
case 'DOCUMENT_ROOT':
|
||||||
$name = env('SCRIPT_NAME');
|
$name = env('SCRIPT_NAME');
|
||||||
$filename = env('SCRIPT_FILENAME');
|
$filename = env('SCRIPT_FILENAME');
|
||||||
|
@ -455,20 +455,27 @@ if (!function_exists('array_combine')) {
|
||||||
$offset = 4;
|
$offset = 4;
|
||||||
}
|
}
|
||||||
return substr($filename, 0, strlen($filename) - (strlen($name) + $offset));
|
return substr($filename, 0, strlen($filename) - (strlen($name) + $offset));
|
||||||
break;
|
break;
|
||||||
case 'PHP_SELF':
|
case 'PHP_SELF':
|
||||||
return str_replace(env('DOCUMENT_ROOT'), '', env('SCRIPT_FILENAME'));
|
return str_replace(env('DOCUMENT_ROOT'), '', env('SCRIPT_FILENAME'));
|
||||||
break;
|
break;
|
||||||
case 'CGI_MODE':
|
case 'CGI_MODE':
|
||||||
return (PHP_SAPI === 'cgi');
|
return (PHP_SAPI === 'cgi');
|
||||||
break;
|
break;
|
||||||
case 'HTTP_BASE':
|
case 'HTTP_BASE':
|
||||||
$host = env('HTTP_HOST');
|
$host = env('HTTP_HOST');
|
||||||
if (substr_count($host, '.') !== 1) {
|
$count = substr_count($host, '.');
|
||||||
return preg_replace('/^([^.])*/i', null, env('HTTP_HOST'));
|
if ($count <= 1) {
|
||||||
|
return '.' . $host;
|
||||||
|
} elseif ($count === 2) {
|
||||||
|
$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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return '.' . $host;
|
return preg_replace('/^([^.])*/i', null, $host);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,13 @@ class BasicsTest extends CakeTestCase {
|
||||||
$__ENV = $_ENV;
|
$__ENV = $_ENV;
|
||||||
|
|
||||||
$_SERVER['HTTP_HOST'] = 'localhost';
|
$_SERVER['HTTP_HOST'] = 'localhost';
|
||||||
$this->assertEqual(env('HTTP_BASE'), '');
|
$this->assertEqual(env('HTTP_BASE'), '.localhost');
|
||||||
|
|
||||||
|
$_SERVER['HTTP_HOST'] = 'com.ar';
|
||||||
|
$this->assertEqual(env('HTTP_BASE'), '.com.ar');
|
||||||
|
|
||||||
|
$_SERVER['HTTP_HOST'] = 'example.ar';
|
||||||
|
$this->assertEqual(env('HTTP_BASE'), '.example.ar');
|
||||||
|
|
||||||
$_SERVER['HTTP_HOST'] = 'example.com';
|
$_SERVER['HTTP_HOST'] = 'example.com';
|
||||||
$this->assertEqual(env('HTTP_BASE'), '.example.com');
|
$this->assertEqual(env('HTTP_BASE'), '.example.com');
|
||||||
|
@ -107,9 +113,21 @@ class BasicsTest extends CakeTestCase {
|
||||||
$_SERVER['HTTP_HOST'] = 'subdomain.example.com';
|
$_SERVER['HTTP_HOST'] = 'subdomain.example.com';
|
||||||
$this->assertEqual(env('HTTP_BASE'), '.example.com');
|
$this->assertEqual(env('HTTP_BASE'), '.example.com');
|
||||||
|
|
||||||
|
$_SERVER['HTTP_HOST'] = 'example.com.ar';
|
||||||
|
$this->assertEqual(env('HTTP_BASE'), '.example.com.ar');
|
||||||
|
|
||||||
|
$_SERVER['HTTP_HOST'] = 'www.example.com.ar';
|
||||||
|
$this->assertEqual(env('HTTP_BASE'), '.example.com.ar');
|
||||||
|
|
||||||
|
$_SERVER['HTTP_HOST'] = 'subdomain.example.com.ar';
|
||||||
|
$this->assertEqual(env('HTTP_BASE'), '.example.com.ar');
|
||||||
|
|
||||||
$_SERVER['HTTP_HOST'] = 'double.subdomain.example.com';
|
$_SERVER['HTTP_HOST'] = 'double.subdomain.example.com';
|
||||||
$this->assertEqual(env('HTTP_BASE'), '.subdomain.example.com');
|
$this->assertEqual(env('HTTP_BASE'), '.subdomain.example.com');
|
||||||
|
|
||||||
|
$_SERVER['HTTP_HOST'] = 'double.subdomain.example.com.ar';
|
||||||
|
$this->assertEqual(env('HTTP_BASE'), '.subdomain.example.com.ar');
|
||||||
|
|
||||||
$_SERVER = $_ENV = array();
|
$_SERVER = $_ENV = array();
|
||||||
|
|
||||||
$_SERVER['SCRIPT_NAME'] = '/a/test/test.php';
|
$_SERVER['SCRIPT_NAME'] = '/a/test/test.php';
|
||||||
|
|
Loading…
Add table
Reference in a new issue