nslookup returns different IP than $_SERVER['SERVER_ADDR']

Without knowing much about system administration, here is in short what I noticed: running nslookup the-site.com returns some IP but running $_SERVER['SERVER_ADDR'] on that site returned different IP.

Could someone give a possible explanation of why is this difference?

Longer version: Why I'm asking this? I was trying to white-list a clients IP form my security plugin (on WordPress), but even after white-listing IP I got from nslookup he still seemed blacklisted. I then tried white-listing the IP returned by $_SERVER['SERVER_ADDR'] (executed on his site) and that did the trick.

Thanks!


Solution 1:

The PHP server variable $_SERVER['SERVER_ADDR'] is set by the webserver on which your PHP code is executed.

There are many situations in which the actual webserver that runs your code will have a different ip-address from the one associated with the DNS domain name in the URL:

  • The site is behind a CDN like CloudFront.
  • The site is behind a load-balancer
  • The site is behind a reverse proxy server
  • etc.