$ _SERVER ['DOCUMENT_ROOT']和$ _SERVER ['HTTP_HOST']之间的区别 [英] Difference between $_SERVER['DOCUMENT_ROOT'] and $_SERVER['HTTP_HOST']

查看:104
本文介绍了$ _SERVER ['DOCUMENT_ROOT']和$ _SERVER ['HTTP_HOST']之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我回来了一个简单的问题(或相关问题).

I am back with a simple question (or related question).

问题很简单,但是我还没有收到答案.我问过许多有不同PHP经验的人.但是我得到的答复是:我没有任何想法.我从未考虑过."使用Google,我找不到与此相关的任何文章.我希望我能在这里得到满意的答复.

The question is simple however I have not received an answer yet. I have asked many people with different experience in PHP. But the response I get is: "I don't have any idea. I've never thought about that." Using Google I have not been able to find any article on this. I hope that I will get a satisfying answer here.

所以问题是:

$_SERVER['DOCUMENT_ROOT']$_SERVER['HTTP_HOST']有什么区别?

一个人比另一个人有什么优势吗?

Are there any advantages of one over the other?

我们应该在哪里使用HTTP_HOST&在哪里使用DOCUMENT_ROOT?

Where should we use HTTP_HOST & where to use DOCUMENT_ROOT?

推荐答案

DOCUMENT_ROOT

此站点的根目录由常规"部分或例如"部分中的"DocumentRoot"指令定义.

The root directory of this site defined by the 'DocumentRoot' directive in the General Section or a section e.g.

DOCUMENT_ROOT=/var/www/example 

HTTP_HOST

主机的基本URL,例如

The base URL of the host e.g.

HTTP_HOST=www.example.com 

文档根目录是服务器上您网站的本地路径; http主机是服务器的主机名.它们是完全不同的.也许您可以澄清您的问题?

The document root is the local path to your website, on your server; The http host is the hostname of the server. They are rather different; perhaps you can clarify your question?

修改: 你说:

案例1:标头('位置:'.$ _SERVER ['DOCUMENT_ROOT'].'/abc.php')

Case 1 : header('Location: '. $_SERVER['DOCUMENT_ROOT'] . '/abc.php')

案例2:header('Location:'.$ _SERVER ['HTTP_HOST'].'/abc.php')

Case 2: header('Location: '. $_SERVER['HTTP_HOST'] . '/abc.php')

我怀疑只有在您的浏览器在提供页面的同一台计算机上运行浏览器时,第一个功能才起作用.

I suspect the first is only going to work if you run your browser on the same machine that's serving the pages.

想象一下是否有人使用他们的Windows机器访问您的网站.然后,您的网络服务器会在HTTP标头中告诉他们:嘿,实际上,重定向此位置:/var/www/example/abc.php."您希望用户的机器做什么?

Imagine if someone else visits your website, using their Windows machine. And your webserver tells them in the HTTP headers, "hey, actually, redirect this location: /var/www/example/abc.php." What do you expect the user's machine to do?

现在,如果您正在谈论类似的事情

Now, if you're talking about something like

<?php include($_SERVER['DOCUMENT_ROOT'] . '/include/abc.php') ?>

vs

<?php include($_SERVER['HTTP_HOST'] . '/include/abc.php') ?>

这可能是有道理的.我怀疑在这种情况下,尽管我不是PHP Guru,但前者可能是首选.

That might make sense. I suspect in this case the former is probably preferred, although I am not a PHP Guru.

这篇关于$ _SERVER ['DOCUMENT_ROOT']和$ _SERVER ['HTTP_HOST']之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆