Hi, if I use the following script and then call the script via file_get_contents() the IP's don't match even though the request comes from that domain. $userIP = $_SERVER['REMOTE_ADDR']; $serverIP = gethostbyname($result['domain']); echo $userIP;echo '|'; echo $serverIP; if ($userIP != $serverIP) { echo 'IP DID NOT MATCH'; exit; } PHP: Any idea why this is?
Sorry, I'm confused, a users IP has nothing to do with a hosted sites IP, so I don't see why they would match ? Maybe I'm wrong understanding your query ?
ok here is a bit more info. I am working on an api. Users will get a key which is linked to a domain. I will run a check to see if the IP of the request matches the domain name the key belongs to.
Just remember, users IP's will change from time to time... you might what to look at $userIP = gethostbyaddr($_SERVER['REMOTE_ADDR']); PHP: ..and strip out the IP because it will change and then check against the ISP name. The only problem with that is, people are using work computers or are mobile with laptops so both the IP's and ISP's will change pending on locations.
? $_SERVER['REMOTE_ADDR']; is the users IP address $_SERVER['SERVER_ADDR']; is the IP on which the script is running on to get an IP of a hosted site <?php $userIP = $_SERVER['SERVER_ADDR']; $serverIP = gethostbyname('example.com'); // put your domain name in here echo $userIP;echo '|'; echo $serverIP; if ($userIP != $serverIP) { echo 'IP DID NOT MATCH'; exit; } ?> PHP:
ok so let me explain again. I am going to offer some API's People will be able to use it for free but they will need a key to use them Each key will be unique for a domain. So if someone wants to use the API they register their domain and get the key. Then they can start to use it. When a request comes in, I want to make sure that the request comes from the server where the domain is located on. Example example.com is located on 12.12.12.12 when a request comes in I take the key and get the corresponding domain. From that domain I get the IP which would be 12.12.12.12 in this example. I want to compare this IP with the IP of the request which should be identical. In my code however the IP's are slightly different so in this example might give 12.12.12.8
SELECT domain FROM domains WHERE domain_key='$key'; Code (markup): Anyway I'll leave it there... good luck with your apps
The request for a key is going to come from the user. The key is going to be used on the user's server. They IP addresses are almost never the same. (They'll be the same if the user is hosting his own server, which is almost never the case.) You'd have to have the user request the key using software that's running on his site in order to get the same IP addresses. All you can do is connect the key to the requested server address (in your database) and only serve data for that key if the remote address - at the time the service is being used - is the one in the database.