获取域名
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Libérer: 2016-07-25 09:08:07
original
1366 Les gens l'ont consulté
我在看那个ecmall核心文件ecmall.php,看到这个函数写得比较清晰,拿出来分享下
- function get_domain() {
- /* 协议 */
- $protocol = (isset($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')) ? 'https://' : 'http://';
-
- /* 域名或IP地址 */
- if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
- $host = $_SERVER['HTTP_X_FORWARDED_HOST'];
- } elseif (isset($_SERVER['HTTP_HOST'])) {
- $host = $_SERVER['HTTP_HOST'];
- } else {
- /* 端口 */
- if (isset($_SERVER['SERVER_PORT'])) {
- $port = ':' . $_SERVER['SERVER_PORT'];
- if ((':80' == $port && 'http://' == $protocol) || (':443' == $port && 'https://' == $protocol)) {
- $port = '';
- }
- } else {
- $port = '';
- }
-
- if (isset($_SERVER['SERVER_NAME'])) {
- $host = $_SERVER['SERVER_NAME'] . $port;
- } elseif (isset($_SERVER['SERVER_ADDR'])) {
- $host = $_SERVER['SERVER_ADDR'] . $port;
- }
- }
-
- return $protocol . $host;
- }
复制代码
|
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Derniers articles par auteur
-
2025-02-26 03:58:14
-
2025-02-26 03:38:10
-
2025-02-26 03:17:10
-
2025-02-26 02:49:09
-
2025-02-26 01:08:13
-
2025-02-26 00:46:10
-
2025-02-25 23:42:08
-
2025-02-25 22:50:13
-
2025-02-25 21:54:11
-
2025-02-25 20:45:11