Difference between $_SERVER['DOCUMENT_ROOT'] and $_SERVER['HTTP_HOST']
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I am back with a simple question (or related question).
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.
So the question is:
What is the difference between $_SERVER['DOCUMENT_ROOT']
and $_SERVER['HTTP_HOST']
?
Are there any advantages of one over the other?
Where should we use HTTP_HOST & where to use DOCUMENT_ROOT?
php
|
show 1 more comment
I am back with a simple question (or related question).
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.
So the question is:
What is the difference between $_SERVER['DOCUMENT_ROOT']
and $_SERVER['HTTP_HOST']
?
Are there any advantages of one over the other?
Where should we use HTTP_HOST & where to use DOCUMENT_ROOT?
php
7
Did you try the documentation for$_SERVER
?
– outis
Aug 29 '11 at 12:04
I dont need to do that...I know what each thing means, but if one using document_root & other using http_host while defining paths, so wat will be the difference between the paths? Which is more used/reliable/where to use what?? as application runs using both. But still there should b sumthng that both are present.
– Aakash Sahai
Aug 29 '11 at 12:57
6
Your questions show you don't seem to know what each means. Each holds different information. You're asking for a comparison between apples and oranges. Would you ask "What's the difference between a street address and a phone number?", or where you would use each?
– outis
Aug 29 '11 at 13:04
k i got u. but if these things are different then y it works similar forCase 1 : header('Location: '. $_SERVER['DOCUMENT_ROOT'] . '/abc.php') Case 2: header('Location: '. $_SERVER['HTTP_HOST'] . '/abc.php')
....as u ol trying to say these are different, i know these are different by definition, but there r working same...
– Aakash Sahai
Aug 29 '11 at 13:09
5
No, no they don't. Neither should work in that context, as neither is a valid absolute URI. The document root is a local path and doesn't have any meaning in URIs. The latter is missing the URI scheme and '//'.
– outis
Aug 29 '11 at 13:10
|
show 1 more comment
I am back with a simple question (or related question).
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.
So the question is:
What is the difference between $_SERVER['DOCUMENT_ROOT']
and $_SERVER['HTTP_HOST']
?
Are there any advantages of one over the other?
Where should we use HTTP_HOST & where to use DOCUMENT_ROOT?
php
I am back with a simple question (or related question).
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.
So the question is:
What is the difference between $_SERVER['DOCUMENT_ROOT']
and $_SERVER['HTTP_HOST']
?
Are there any advantages of one over the other?
Where should we use HTTP_HOST & where to use DOCUMENT_ROOT?
php
php
edited Aug 29 '11 at 13:11
Bjarke Freund-Hansen
12.6k1884124
12.6k1884124
asked Aug 29 '11 at 12:02
Aakash SahaiAakash Sahai
2,64752238
2,64752238
7
Did you try the documentation for$_SERVER
?
– outis
Aug 29 '11 at 12:04
I dont need to do that...I know what each thing means, but if one using document_root & other using http_host while defining paths, so wat will be the difference between the paths? Which is more used/reliable/where to use what?? as application runs using both. But still there should b sumthng that both are present.
– Aakash Sahai
Aug 29 '11 at 12:57
6
Your questions show you don't seem to know what each means. Each holds different information. You're asking for a comparison between apples and oranges. Would you ask "What's the difference between a street address and a phone number?", or where you would use each?
– outis
Aug 29 '11 at 13:04
k i got u. but if these things are different then y it works similar forCase 1 : header('Location: '. $_SERVER['DOCUMENT_ROOT'] . '/abc.php') Case 2: header('Location: '. $_SERVER['HTTP_HOST'] . '/abc.php')
....as u ol trying to say these are different, i know these are different by definition, but there r working same...
– Aakash Sahai
Aug 29 '11 at 13:09
5
No, no they don't. Neither should work in that context, as neither is a valid absolute URI. The document root is a local path and doesn't have any meaning in URIs. The latter is missing the URI scheme and '//'.
– outis
Aug 29 '11 at 13:10
|
show 1 more comment
7
Did you try the documentation for$_SERVER
?
– outis
Aug 29 '11 at 12:04
I dont need to do that...I know what each thing means, but if one using document_root & other using http_host while defining paths, so wat will be the difference between the paths? Which is more used/reliable/where to use what?? as application runs using both. But still there should b sumthng that both are present.
– Aakash Sahai
Aug 29 '11 at 12:57
6
Your questions show you don't seem to know what each means. Each holds different information. You're asking for a comparison between apples and oranges. Would you ask "What's the difference between a street address and a phone number?", or where you would use each?
– outis
Aug 29 '11 at 13:04
k i got u. but if these things are different then y it works similar forCase 1 : header('Location: '. $_SERVER['DOCUMENT_ROOT'] . '/abc.php') Case 2: header('Location: '. $_SERVER['HTTP_HOST'] . '/abc.php')
....as u ol trying to say these are different, i know these are different by definition, but there r working same...
– Aakash Sahai
Aug 29 '11 at 13:09
5
No, no they don't. Neither should work in that context, as neither is a valid absolute URI. The document root is a local path and doesn't have any meaning in URIs. The latter is missing the URI scheme and '//'.
– outis
Aug 29 '11 at 13:10
7
7
Did you try the documentation for
$_SERVER
?– outis
Aug 29 '11 at 12:04
Did you try the documentation for
$_SERVER
?– outis
Aug 29 '11 at 12:04
I dont need to do that...I know what each thing means, but if one using document_root & other using http_host while defining paths, so wat will be the difference between the paths? Which is more used/reliable/where to use what?? as application runs using both. But still there should b sumthng that both are present.
– Aakash Sahai
Aug 29 '11 at 12:57
I dont need to do that...I know what each thing means, but if one using document_root & other using http_host while defining paths, so wat will be the difference between the paths? Which is more used/reliable/where to use what?? as application runs using both. But still there should b sumthng that both are present.
– Aakash Sahai
Aug 29 '11 at 12:57
6
6
Your questions show you don't seem to know what each means. Each holds different information. You're asking for a comparison between apples and oranges. Would you ask "What's the difference between a street address and a phone number?", or where you would use each?
– outis
Aug 29 '11 at 13:04
Your questions show you don't seem to know what each means. Each holds different information. You're asking for a comparison between apples and oranges. Would you ask "What's the difference between a street address and a phone number?", or where you would use each?
– outis
Aug 29 '11 at 13:04
k i got u. but if these things are different then y it works similar for
Case 1 : header('Location: '. $_SERVER['DOCUMENT_ROOT'] . '/abc.php') Case 2: header('Location: '. $_SERVER['HTTP_HOST'] . '/abc.php')
....as u ol trying to say these are different, i know these are different by definition, but there r working same...– Aakash Sahai
Aug 29 '11 at 13:09
k i got u. but if these things are different then y it works similar for
Case 1 : header('Location: '. $_SERVER['DOCUMENT_ROOT'] . '/abc.php') Case 2: header('Location: '. $_SERVER['HTTP_HOST'] . '/abc.php')
....as u ol trying to say these are different, i know these are different by definition, but there r working same...– Aakash Sahai
Aug 29 '11 at 13:09
5
5
No, no they don't. Neither should work in that context, as neither is a valid absolute URI. The document root is a local path and doesn't have any meaning in URIs. The latter is missing the URI scheme and '//'.
– outis
Aug 29 '11 at 13:10
No, no they don't. Neither should work in that context, as neither is a valid absolute URI. The document root is a local path and doesn't have any meaning in URIs. The latter is missing the URI scheme and '//'.
– outis
Aug 29 '11 at 13:10
|
show 1 more comment
6 Answers
6
active
oldest
votes
DOCUMENT_ROOT
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
The base URL of the host e.g.
HTTP_HOST=www.example.com
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?
Edit:
You said:
Case 1 : header('Location: '. $_SERVER['DOCUMENT_ROOT'] . '/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.
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') ?>
That might make sense. I suspect in this case the former is probably preferred, although I am not a PHP Guru.
I think u all didn't get my point. I know what is document root and what http_host do...but i have used HTTP_HOST in all my project, but my senior said that u should use Document_root, it is more reliable. I asked him, so he told me search for it. Now I had only asked that y should I go for document root, instead of HTTP_HOST when defining path.
– Aakash Sahai
Aug 29 '11 at 12:49
add a comment |
Eh, what's the question? DOCUMENT_ROOT
contains the path to current web, in my case /home/www
. HTTP_HOST
contains testing.local
, as it runs on local domain. The difference is obvious, isn't it?
I cannot figure out where you could interchange those two, so why should you consider advantages?
I think u all didn't get my point. I know what is document root and what http_host do...but i have used HTTP_HOST in all my project, but my senior said that u should use Document_root, it is more reliable. I asked him, so he told me search for it. Now I had only asked that y should I go for document root, instead of HTTP_HOST when defining path.
– Aakash Sahai
Aug 29 '11 at 12:50
12
So tell your senior he is an idiot.
– nothrow
Sep 8 '11 at 15:01
add a comment |
HTTP_HOST
will give you URL of the host, e.g. domain.com
DOCUMENT_ROOT
will give you absolute path to document root of the website in server's file system, e.g. /var/www/domain/
Btw, have you tried looking at PHP's manual, specifically $_SERVER
? Everything is explanied there.
HTTP_HOST
isn't a URL, it's just a (wait for it) host name. There's no 'http:' scheme.
– outis
Aug 29 '11 at 12:09
@outis right, thank you, amended
– J0HN
Aug 29 '11 at 12:10
I think u all didn't get my point. I know what is document root and what http_host do...but i have used HTTP_HOST in all my project, but my senior said that u should use Document_root, it is more reliable. I asked him, so he told me search for it. Now I had only asked that y should I go for document root, instead of HTTP_HOST when defining path.
– Aakash Sahai
Aug 29 '11 at 12:51
3
This means that you or your senior does not understand what's the difference between them. Could you provide some code samples where you useHTTP_HOST
?
– J0HN
Aug 29 '11 at 12:53
2
Case 1 is incorrect. Case 2 is OK. If in your setup case 1 is working as expected - it's something strange.
– J0HN
Aug 29 '11 at 13:26
|
show 1 more comment
<?php include($_SERVER['DOCUMENT_ROOT'] . '/include/abc.php') ?>
should be used for including the files in another file.
header('Location: '. $_SERVER['HTTP_HOST'] . '/abc.php')
should be used for hyperlinking
1
It's the other way around.
– Pampy
Aug 5 '16 at 13:27
add a comment |
if you want domain path like 'example.com', you can use "HTTP_HOST"
if you want folder '/public_html/foldername/' path you can use
"DOCUMENT_ROOT"
if you want folder and file path use document_root like public_html/folderpath/files if you want the url web path then use http_host like www.website.com
– Suhasini
Sep 8 '18 at 10:09
add a comment |
$_SERVER ['HTTP_HOST']
returns the domain url
a.g. www.example.com
While $_SERVER['DOCUMENT_ROOT']
returns the roof of current web..
Such as
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7229783%2fdifference-between-serverdocument-root-and-serverhttp-host%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
DOCUMENT_ROOT
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
The base URL of the host e.g.
HTTP_HOST=www.example.com
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?
Edit:
You said:
Case 1 : header('Location: '. $_SERVER['DOCUMENT_ROOT'] . '/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.
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') ?>
That might make sense. I suspect in this case the former is probably preferred, although I am not a PHP Guru.
I think u all didn't get my point. I know what is document root and what http_host do...but i have used HTTP_HOST in all my project, but my senior said that u should use Document_root, it is more reliable. I asked him, so he told me search for it. Now I had only asked that y should I go for document root, instead of HTTP_HOST when defining path.
– Aakash Sahai
Aug 29 '11 at 12:49
add a comment |
DOCUMENT_ROOT
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
The base URL of the host e.g.
HTTP_HOST=www.example.com
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?
Edit:
You said:
Case 1 : header('Location: '. $_SERVER['DOCUMENT_ROOT'] . '/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.
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') ?>
That might make sense. I suspect in this case the former is probably preferred, although I am not a PHP Guru.
I think u all didn't get my point. I know what is document root and what http_host do...but i have used HTTP_HOST in all my project, but my senior said that u should use Document_root, it is more reliable. I asked him, so he told me search for it. Now I had only asked that y should I go for document root, instead of HTTP_HOST when defining path.
– Aakash Sahai
Aug 29 '11 at 12:49
add a comment |
DOCUMENT_ROOT
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
The base URL of the host e.g.
HTTP_HOST=www.example.com
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?
Edit:
You said:
Case 1 : header('Location: '. $_SERVER['DOCUMENT_ROOT'] . '/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.
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') ?>
That might make sense. I suspect in this case the former is probably preferred, although I am not a PHP Guru.
DOCUMENT_ROOT
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
The base URL of the host e.g.
HTTP_HOST=www.example.com
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?
Edit:
You said:
Case 1 : header('Location: '. $_SERVER['DOCUMENT_ROOT'] . '/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.
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') ?>
That might make sense. I suspect in this case the former is probably preferred, although I am not a PHP Guru.
edited Aug 29 '11 at 15:10
answered Aug 29 '11 at 12:06
John LedbetterJohn Ledbetter
10.4k4371
10.4k4371
I think u all didn't get my point. I know what is document root and what http_host do...but i have used HTTP_HOST in all my project, but my senior said that u should use Document_root, it is more reliable. I asked him, so he told me search for it. Now I had only asked that y should I go for document root, instead of HTTP_HOST when defining path.
– Aakash Sahai
Aug 29 '11 at 12:49
add a comment |
I think u all didn't get my point. I know what is document root and what http_host do...but i have used HTTP_HOST in all my project, but my senior said that u should use Document_root, it is more reliable. I asked him, so he told me search for it. Now I had only asked that y should I go for document root, instead of HTTP_HOST when defining path.
– Aakash Sahai
Aug 29 '11 at 12:49
I think u all didn't get my point. I know what is document root and what http_host do...but i have used HTTP_HOST in all my project, but my senior said that u should use Document_root, it is more reliable. I asked him, so he told me search for it. Now I had only asked that y should I go for document root, instead of HTTP_HOST when defining path.
– Aakash Sahai
Aug 29 '11 at 12:49
I think u all didn't get my point. I know what is document root and what http_host do...but i have used HTTP_HOST in all my project, but my senior said that u should use Document_root, it is more reliable. I asked him, so he told me search for it. Now I had only asked that y should I go for document root, instead of HTTP_HOST when defining path.
– Aakash Sahai
Aug 29 '11 at 12:49
add a comment |
Eh, what's the question? DOCUMENT_ROOT
contains the path to current web, in my case /home/www
. HTTP_HOST
contains testing.local
, as it runs on local domain. The difference is obvious, isn't it?
I cannot figure out where you could interchange those two, so why should you consider advantages?
I think u all didn't get my point. I know what is document root and what http_host do...but i have used HTTP_HOST in all my project, but my senior said that u should use Document_root, it is more reliable. I asked him, so he told me search for it. Now I had only asked that y should I go for document root, instead of HTTP_HOST when defining path.
– Aakash Sahai
Aug 29 '11 at 12:50
12
So tell your senior he is an idiot.
– nothrow
Sep 8 '11 at 15:01
add a comment |
Eh, what's the question? DOCUMENT_ROOT
contains the path to current web, in my case /home/www
. HTTP_HOST
contains testing.local
, as it runs on local domain. The difference is obvious, isn't it?
I cannot figure out where you could interchange those two, so why should you consider advantages?
I think u all didn't get my point. I know what is document root and what http_host do...but i have used HTTP_HOST in all my project, but my senior said that u should use Document_root, it is more reliable. I asked him, so he told me search for it. Now I had only asked that y should I go for document root, instead of HTTP_HOST when defining path.
– Aakash Sahai
Aug 29 '11 at 12:50
12
So tell your senior he is an idiot.
– nothrow
Sep 8 '11 at 15:01
add a comment |
Eh, what's the question? DOCUMENT_ROOT
contains the path to current web, in my case /home/www
. HTTP_HOST
contains testing.local
, as it runs on local domain. The difference is obvious, isn't it?
I cannot figure out where you could interchange those two, so why should you consider advantages?
Eh, what's the question? DOCUMENT_ROOT
contains the path to current web, in my case /home/www
. HTTP_HOST
contains testing.local
, as it runs on local domain. The difference is obvious, isn't it?
I cannot figure out where you could interchange those two, so why should you consider advantages?
answered Aug 29 '11 at 12:05
nothrownothrow
11.8k43986
11.8k43986
I think u all didn't get my point. I know what is document root and what http_host do...but i have used HTTP_HOST in all my project, but my senior said that u should use Document_root, it is more reliable. I asked him, so he told me search for it. Now I had only asked that y should I go for document root, instead of HTTP_HOST when defining path.
– Aakash Sahai
Aug 29 '11 at 12:50
12
So tell your senior he is an idiot.
– nothrow
Sep 8 '11 at 15:01
add a comment |
I think u all didn't get my point. I know what is document root and what http_host do...but i have used HTTP_HOST in all my project, but my senior said that u should use Document_root, it is more reliable. I asked him, so he told me search for it. Now I had only asked that y should I go for document root, instead of HTTP_HOST when defining path.
– Aakash Sahai
Aug 29 '11 at 12:50
12
So tell your senior he is an idiot.
– nothrow
Sep 8 '11 at 15:01
I think u all didn't get my point. I know what is document root and what http_host do...but i have used HTTP_HOST in all my project, but my senior said that u should use Document_root, it is more reliable. I asked him, so he told me search for it. Now I had only asked that y should I go for document root, instead of HTTP_HOST when defining path.
– Aakash Sahai
Aug 29 '11 at 12:50
I think u all didn't get my point. I know what is document root and what http_host do...but i have used HTTP_HOST in all my project, but my senior said that u should use Document_root, it is more reliable. I asked him, so he told me search for it. Now I had only asked that y should I go for document root, instead of HTTP_HOST when defining path.
– Aakash Sahai
Aug 29 '11 at 12:50
12
12
So tell your senior he is an idiot.
– nothrow
Sep 8 '11 at 15:01
So tell your senior he is an idiot.
– nothrow
Sep 8 '11 at 15:01
add a comment |
HTTP_HOST
will give you URL of the host, e.g. domain.com
DOCUMENT_ROOT
will give you absolute path to document root of the website in server's file system, e.g. /var/www/domain/
Btw, have you tried looking at PHP's manual, specifically $_SERVER
? Everything is explanied there.
HTTP_HOST
isn't a URL, it's just a (wait for it) host name. There's no 'http:' scheme.
– outis
Aug 29 '11 at 12:09
@outis right, thank you, amended
– J0HN
Aug 29 '11 at 12:10
I think u all didn't get my point. I know what is document root and what http_host do...but i have used HTTP_HOST in all my project, but my senior said that u should use Document_root, it is more reliable. I asked him, so he told me search for it. Now I had only asked that y should I go for document root, instead of HTTP_HOST when defining path.
– Aakash Sahai
Aug 29 '11 at 12:51
3
This means that you or your senior does not understand what's the difference between them. Could you provide some code samples where you useHTTP_HOST
?
– J0HN
Aug 29 '11 at 12:53
2
Case 1 is incorrect. Case 2 is OK. If in your setup case 1 is working as expected - it's something strange.
– J0HN
Aug 29 '11 at 13:26
|
show 1 more comment
HTTP_HOST
will give you URL of the host, e.g. domain.com
DOCUMENT_ROOT
will give you absolute path to document root of the website in server's file system, e.g. /var/www/domain/
Btw, have you tried looking at PHP's manual, specifically $_SERVER
? Everything is explanied there.
HTTP_HOST
isn't a URL, it's just a (wait for it) host name. There's no 'http:' scheme.
– outis
Aug 29 '11 at 12:09
@outis right, thank you, amended
– J0HN
Aug 29 '11 at 12:10
I think u all didn't get my point. I know what is document root and what http_host do...but i have used HTTP_HOST in all my project, but my senior said that u should use Document_root, it is more reliable. I asked him, so he told me search for it. Now I had only asked that y should I go for document root, instead of HTTP_HOST when defining path.
– Aakash Sahai
Aug 29 '11 at 12:51
3
This means that you or your senior does not understand what's the difference between them. Could you provide some code samples where you useHTTP_HOST
?
– J0HN
Aug 29 '11 at 12:53
2
Case 1 is incorrect. Case 2 is OK. If in your setup case 1 is working as expected - it's something strange.
– J0HN
Aug 29 '11 at 13:26
|
show 1 more comment
HTTP_HOST
will give you URL of the host, e.g. domain.com
DOCUMENT_ROOT
will give you absolute path to document root of the website in server's file system, e.g. /var/www/domain/
Btw, have you tried looking at PHP's manual, specifically $_SERVER
? Everything is explanied there.
HTTP_HOST
will give you URL of the host, e.g. domain.com
DOCUMENT_ROOT
will give you absolute path to document root of the website in server's file system, e.g. /var/www/domain/
Btw, have you tried looking at PHP's manual, specifically $_SERVER
? Everything is explanied there.
edited Aug 29 '11 at 12:10
answered Aug 29 '11 at 12:05
J0HNJ0HN
20k33774
20k33774
HTTP_HOST
isn't a URL, it's just a (wait for it) host name. There's no 'http:' scheme.
– outis
Aug 29 '11 at 12:09
@outis right, thank you, amended
– J0HN
Aug 29 '11 at 12:10
I think u all didn't get my point. I know what is document root and what http_host do...but i have used HTTP_HOST in all my project, but my senior said that u should use Document_root, it is more reliable. I asked him, so he told me search for it. Now I had only asked that y should I go for document root, instead of HTTP_HOST when defining path.
– Aakash Sahai
Aug 29 '11 at 12:51
3
This means that you or your senior does not understand what's the difference between them. Could you provide some code samples where you useHTTP_HOST
?
– J0HN
Aug 29 '11 at 12:53
2
Case 1 is incorrect. Case 2 is OK. If in your setup case 1 is working as expected - it's something strange.
– J0HN
Aug 29 '11 at 13:26
|
show 1 more comment
HTTP_HOST
isn't a URL, it's just a (wait for it) host name. There's no 'http:' scheme.
– outis
Aug 29 '11 at 12:09
@outis right, thank you, amended
– J0HN
Aug 29 '11 at 12:10
I think u all didn't get my point. I know what is document root and what http_host do...but i have used HTTP_HOST in all my project, but my senior said that u should use Document_root, it is more reliable. I asked him, so he told me search for it. Now I had only asked that y should I go for document root, instead of HTTP_HOST when defining path.
– Aakash Sahai
Aug 29 '11 at 12:51
3
This means that you or your senior does not understand what's the difference between them. Could you provide some code samples where you useHTTP_HOST
?
– J0HN
Aug 29 '11 at 12:53
2
Case 1 is incorrect. Case 2 is OK. If in your setup case 1 is working as expected - it's something strange.
– J0HN
Aug 29 '11 at 13:26
HTTP_HOST
isn't a URL, it's just a (wait for it) host name. There's no 'http:' scheme.– outis
Aug 29 '11 at 12:09
HTTP_HOST
isn't a URL, it's just a (wait for it) host name. There's no 'http:' scheme.– outis
Aug 29 '11 at 12:09
@outis right, thank you, amended
– J0HN
Aug 29 '11 at 12:10
@outis right, thank you, amended
– J0HN
Aug 29 '11 at 12:10
I think u all didn't get my point. I know what is document root and what http_host do...but i have used HTTP_HOST in all my project, but my senior said that u should use Document_root, it is more reliable. I asked him, so he told me search for it. Now I had only asked that y should I go for document root, instead of HTTP_HOST when defining path.
– Aakash Sahai
Aug 29 '11 at 12:51
I think u all didn't get my point. I know what is document root and what http_host do...but i have used HTTP_HOST in all my project, but my senior said that u should use Document_root, it is more reliable. I asked him, so he told me search for it. Now I had only asked that y should I go for document root, instead of HTTP_HOST when defining path.
– Aakash Sahai
Aug 29 '11 at 12:51
3
3
This means that you or your senior does not understand what's the difference between them. Could you provide some code samples where you use
HTTP_HOST
?– J0HN
Aug 29 '11 at 12:53
This means that you or your senior does not understand what's the difference between them. Could you provide some code samples where you use
HTTP_HOST
?– J0HN
Aug 29 '11 at 12:53
2
2
Case 1 is incorrect. Case 2 is OK. If in your setup case 1 is working as expected - it's something strange.
– J0HN
Aug 29 '11 at 13:26
Case 1 is incorrect. Case 2 is OK. If in your setup case 1 is working as expected - it's something strange.
– J0HN
Aug 29 '11 at 13:26
|
show 1 more comment
<?php include($_SERVER['DOCUMENT_ROOT'] . '/include/abc.php') ?>
should be used for including the files in another file.
header('Location: '. $_SERVER['HTTP_HOST'] . '/abc.php')
should be used for hyperlinking
1
It's the other way around.
– Pampy
Aug 5 '16 at 13:27
add a comment |
<?php include($_SERVER['DOCUMENT_ROOT'] . '/include/abc.php') ?>
should be used for including the files in another file.
header('Location: '. $_SERVER['HTTP_HOST'] . '/abc.php')
should be used for hyperlinking
1
It's the other way around.
– Pampy
Aug 5 '16 at 13:27
add a comment |
<?php include($_SERVER['DOCUMENT_ROOT'] . '/include/abc.php') ?>
should be used for including the files in another file.
header('Location: '. $_SERVER['HTTP_HOST'] . '/abc.php')
should be used for hyperlinking
<?php include($_SERVER['DOCUMENT_ROOT'] . '/include/abc.php') ?>
should be used for including the files in another file.
header('Location: '. $_SERVER['HTTP_HOST'] . '/abc.php')
should be used for hyperlinking
edited Jul 21 '18 at 14:11
dev_masta
790513
790513
answered Nov 13 '11 at 17:03
AdiAdi
2,63921522
2,63921522
1
It's the other way around.
– Pampy
Aug 5 '16 at 13:27
add a comment |
1
It's the other way around.
– Pampy
Aug 5 '16 at 13:27
1
1
It's the other way around.
– Pampy
Aug 5 '16 at 13:27
It's the other way around.
– Pampy
Aug 5 '16 at 13:27
add a comment |
if you want domain path like 'example.com', you can use "HTTP_HOST"
if you want folder '/public_html/foldername/' path you can use
"DOCUMENT_ROOT"
if you want folder and file path use document_root like public_html/folderpath/files if you want the url web path then use http_host like www.website.com
– Suhasini
Sep 8 '18 at 10:09
add a comment |
if you want domain path like 'example.com', you can use "HTTP_HOST"
if you want folder '/public_html/foldername/' path you can use
"DOCUMENT_ROOT"
if you want folder and file path use document_root like public_html/folderpath/files if you want the url web path then use http_host like www.website.com
– Suhasini
Sep 8 '18 at 10:09
add a comment |
if you want domain path like 'example.com', you can use "HTTP_HOST"
if you want folder '/public_html/foldername/' path you can use
"DOCUMENT_ROOT"
if you want domain path like 'example.com', you can use "HTTP_HOST"
if you want folder '/public_html/foldername/' path you can use
"DOCUMENT_ROOT"
edited Feb 26 '18 at 9:14
David
12.2k64059
12.2k64059
answered Feb 26 '18 at 7:47
SuhasiniSuhasini
112
112
if you want folder and file path use document_root like public_html/folderpath/files if you want the url web path then use http_host like www.website.com
– Suhasini
Sep 8 '18 at 10:09
add a comment |
if you want folder and file path use document_root like public_html/folderpath/files if you want the url web path then use http_host like www.website.com
– Suhasini
Sep 8 '18 at 10:09
if you want folder and file path use document_root like public_html/folderpath/files if you want the url web path then use http_host like www.website.com
– Suhasini
Sep 8 '18 at 10:09
if you want folder and file path use document_root like public_html/folderpath/files if you want the url web path then use http_host like www.website.com
– Suhasini
Sep 8 '18 at 10:09
add a comment |
$_SERVER ['HTTP_HOST']
returns the domain url
a.g. www.example.com
While $_SERVER['DOCUMENT_ROOT']
returns the roof of current web..
Such as
add a comment |
$_SERVER ['HTTP_HOST']
returns the domain url
a.g. www.example.com
While $_SERVER['DOCUMENT_ROOT']
returns the roof of current web..
Such as
add a comment |
$_SERVER ['HTTP_HOST']
returns the domain url
a.g. www.example.com
While $_SERVER['DOCUMENT_ROOT']
returns the roof of current web..
Such as
$_SERVER ['HTTP_HOST']
returns the domain url
a.g. www.example.com
While $_SERVER['DOCUMENT_ROOT']
returns the roof of current web..
Such as
edited Nov 22 '18 at 15:45
community wiki
4 revs, 2 users 76%
Tahridabbas
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7229783%2fdifference-between-serverdocument-root-and-serverhttp-host%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
7
Did you try the documentation for
$_SERVER
?– outis
Aug 29 '11 at 12:04
I dont need to do that...I know what each thing means, but if one using document_root & other using http_host while defining paths, so wat will be the difference between the paths? Which is more used/reliable/where to use what?? as application runs using both. But still there should b sumthng that both are present.
– Aakash Sahai
Aug 29 '11 at 12:57
6
Your questions show you don't seem to know what each means. Each holds different information. You're asking for a comparison between apples and oranges. Would you ask "What's the difference between a street address and a phone number?", or where you would use each?
– outis
Aug 29 '11 at 13:04
k i got u. but if these things are different then y it works similar for
Case 1 : header('Location: '. $_SERVER['DOCUMENT_ROOT'] . '/abc.php') Case 2: header('Location: '. $_SERVER['HTTP_HOST'] . '/abc.php')
....as u ol trying to say these are different, i know these are different by definition, but there r working same...– Aakash Sahai
Aug 29 '11 at 13:09
5
No, no they don't. Neither should work in that context, as neither is a valid absolute URI. The document root is a local path and doesn't have any meaning in URIs. The latter is missing the URI scheme and '//'.
– outis
Aug 29 '11 at 13:10