Server Address vs DNS

Reply

Join Date: Jan 2009
Posts: 3
Reputation: finance-blog is an unknown quantity at this point 
Solved Threads: 0
finance-blog finance-blog is offline Offline
Newbie Poster

Server Address vs DNS

 
0
  #1
Jan 2nd, 2009
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.

  1. $ip = gethostbyname($domain);
  2.  
  3. if ($ip != $_SERVER["REMOTE_ADDR"])
  4. { echo "URL does not match requesting IP address<br>\n";
  5. echo "$domain - $ip<br>\n";
  6. echo $_SERVER["REMOTE_ADDR"]."<br>\n";
  7. exit;
  8. }

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?
Last edited by finance-blog; Jan 2nd, 2009 at 4:02 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 19
Reputation: hakimkal is an unknown quantity at this point 
Solved Threads: 4
hakimkal hakimkal is offline Offline
Newbie Poster

Re: Server Address vs DNS

 
0
  #2
Jan 3rd, 2009
try these line and see what you get?
  1. <?php
  2.  
  3. $hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']) ;
  4.  
  5. ?>

best of luck with the job.
Last edited by peter_budo; Jan 6th, 2009 at 2:14 pm. Reason: Code tag correction please [code=php] instead of [code syntax="php"]
abdoolherkym!
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 3
Reputation: finance-blog is an unknown quantity at this point 
Solved Threads: 0
finance-blog finance-blog is offline Offline
Newbie Poster

Re: Server Address vs DNS

 
0
  #3
Jan 4th, 2009
Surely on a shared serverm that would just give you the name of the shared server, not the domain name that is calling you.
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,050
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 65
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: Server Address vs DNS

 
0
  #4
Jan 6th, 2009
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
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,050
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 65
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: Server Address vs DNS

 
0
  #5
Jan 6th, 2009
Also take a look at:
http://pear.php.net/package/Net_DNS

Works with windows also.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC