How to compare IP and URL and see if they go to the same site

How can I see in PHP if the IP address and URL are on the same website?

I used Curl to get content on a website and compared with each other to see if the site matches. If it is not the same, it will tell a lie. It didn’t work!

+4
source share
2 answers

You can use gethostbynamefor this.

for example

$ip = "1.2.3.4";
$domain = "www.example.com";

if(gethostbyname($domain) == $ip) { echo 'IP/URL Match.'; }

gethostbyname ()

Edit:

Quentin noted that this does not mean that they will return to the correct website, which is correct. I misunderstood the beginning of the message. They will only go to the correct website if the default virtual host for the IP address points to the same document root as the URL.

2:

, , - , , , , , - , , .

, , , - $_SERVER['SERVER_NAME'] - .

+4

, :

VPS , user1, user2 user3. IP- VPS , : Apache - .

VPS , IP vps user1 vps. : Apache , -.

, ?

+2
source

All Articles