DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   PHP (http://www.daniweb.com/forums/forum17.html)
-   -   Server Address vs DNS (http://www.daniweb.com/forums/thread165706.html)

finance-blog Jan 2nd, 2009 4:01 pm
Server Address vs DNS
 
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";
        exit;
}

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?

hakimkal Jan 3rd, 2009 5:06 pm
Re: Server Address vs DNS
 
try these line and see what you get?
<?php

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

?>

best of luck with the job.

finance-blog Jan 4th, 2009 3:24 pm
Re: Server Address vs DNS
 
Surely on a shared serverm that would just give you the name of the shared server, not the domain name that is calling you.

digital-ether Jan 6th, 2009 11:30 am
Re: Server Address vs DNS
 
The domain probably has more then one IP.

Try:

http://www.php.net/manual/en/functio...ostbynamel.php

and do a in_array() on the list of IPs.
http://www.php.net/in_array

digital-ether Jan 6th, 2009 11:31 am
Re: Server Address vs DNS
 
Also take a look at:
http://pear.php.net/package/Net_DNS

Works with windows also.


All times are GMT -4. The time now is 4:00 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC