I want to check the request is come from which URL LIKE --- www.mysite.com or bussiness.mysite.com
.How can we check it,as $_SERVER['HTTP_HOST'] gives whole URL .
Thanks .
Asked
Active
Viewed 595 times
1

Vaibhav Agarwal
- 238
- 5
- 19
-
1then what is the problem ? – swapnesh Apr 18 '13 at 06:07
-
use a regex to match and extract? – 1337holiday Apr 18 '13 at 06:08
-
1If `$_SERVER['HTTP_HOST']` contains a URL then there is some serious problem with your clients / proxies setup! php's documentation clearly states that the value of that field is the content of the http `Host:` header. If a client puts a url in there is _really_ is broken! What does `$_SERVER['SERVER_NAME]` contain? – arkascha Apr 18 '13 at 06:10
-
http://stackoverflow.com/questions/5292937/php-function-to-get-the-subdomain-of-a-url – Ravindra Shekhawat Apr 18 '13 at 06:12
2 Answers
1
The thing you want is Subdomain of your url. Use this
$subdomain = array_shift(explode(".",$_SERVER['HTTP_HOST']));

chandresh_cool
- 11,753
- 3
- 30
- 45
-
2I'd put a thought into this question first: why is there such strange / invalid content in there? – arkascha Apr 18 '13 at 06:12
-
-
$_REQUEST['HTTP_HOST'] should not contain a URL but the content of the requests `Host:` header. If it suddenly contains a url then something is _really_ borked in the setup, most likely on client or proxy side. So what you do is trying to cure a symptom instead of the cause. – arkascha Apr 18 '13 at 07:42
1
$domain = $_SERVER['HTTP_HOST'];
$path = $_SERVER['SCRIPT_NAME'];
$queryString = $_SERVER['QUERY_STRING'];
$url = "http://" . $domain . $path . "?" . $queryString;
echo "The current URL is: " . $url . "";
visit :http://www.2basetechnologies.com/

chitra
- 11
- 2