RE: [phpXperts] ***Detecting requested domain & IP
I hope you asking you wanted to record the detection from another-domain.com in my-domain.com
Since you included database.php in your another-domain.com from my-domain.com, so you can write the code in database.php @ my-domain.com
If ($_SERVER[‘HTTP_HOST’]==”another-domain.com”) do the code else do the code…..
I hope you will the path you want to reach
Project Manager (Web Development),
Dear PHP Xperts,
Let my domain is www.my-domain.com & my IP is 192.168.25.36
Let another domain is www.another-domain.com & its IP is 101.256.23.43
A PHP file is in www.another-domain.com contains the following code:
<?php include “http://www.my-domain.com/header/database.php”; ?>
<link rel='stylesheet' type='text/css' href='http://www.my-domain.com/header/style/common/css/misc.css' />
Now how could I detect that the request to my server (www.my-domain.com & 192.168.25.36) has come, is from www.another-domain.com & 101.256.23.43
*My priority is domain name detection. That is from which domain a request has come.
A. N. M. Saiful Islam
Chief Executive Officer
Founder & Managing Director
Director and Head of the IT Division
ICT & eShop Development Ltd
389, Askardigi, West Side, Chittagong
You rock. That's why Blockbuster's offering you one month of Blockbuster Total Access, No Cost.
If http://www.my-domain.com/header/database.php is requested, in database.php $_SERVER['HTTP_HOST'] will contain "www.my-domain.com". It doesnt depend on the request url at all. it depends on the Host: header that is sent to apache sever on www.my-domain.com. php just captures the Host header and put it in HTTP_HOST variable. if you send a XXX header, php will put it in HTTP_XXX server variable. So it wont work for you.
However you can use $_SERVER['REMOTE_ADDR']. It will contain 101.256.23.43. This is the IP of the domain that is requesting the URI on your server. But you can not detect which domain is requested. because connections are not created by domain. they are created by IP. Though you can use gethostbyaddr() type function to reverse the IP to domain mapping. that will only work if 101.256.23.43 has only one domain. But normally in shared hosting lots of domain is created by domain pointer. In that case gethostbyaddr() wont retrieve the correct domain name.
So you have to rely on IP address only.
Hope that helps.