I have some code that is called from with other files, using readfile so there is no referer etc.

To authenticate that the request is where it should be from, the php is passed a calling url as part of it parameters.

The idea is that I can then check the calling IP is from the correct machine. This works fine in most cases, however on some machines (I'm guessing VPS) the Server address is not what the DNS returns even though the domain name is hosted on that PC.

Here is my code.

$ip = gethostbyname($domain);

if ($ip != $_SERVER["REMOTE_ADDR"])
{	echo "URL does not match requesting IP address<br>\n";
	echo "$domain - $ip<br>\n";
	echo $_SERVER["REMOTE_ADDR"]."<br>\n";

In theory the REMOTE_ADDR and the IP returned from gethostbyname should match but they don't anybody any ideas how to get round this?

9 Years
Discussion Span
Last Post by digital-ether

try these line and see what you get?


$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']) ;


best of luck with the job.


Surely on a shared serverm that would just give you the name of the shared server, not the domain name that is calling you.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.