It appears that jsonip.appspot.com is over quota. What alternatives do you have?
- http://jsonip.com/
- http://freegeoip.appspot.com/ – This one is currently over quota as well
Have another? Post it below!
Or, Write Your Own with PHP:
<?php $ip = !empty($_SERVER['REMOTE_ADDR'])?$_SERVER['REMOTE_ADDR']:''; $json = array(); $json['ip'] = $ip; if(!empty($_GET['callback'])){ //remove non standard characters if callback is set $callback = preg_replace('#[^a-zA-Z0-9\-\_]#','',$_GET['callback']); } if(!empty($callback)){ //if callback still exists after cleaning up non standard characters //then call that function with the IP data echo $callback.'('.json_encode($json).');'; }else{ //else echo the IP data echo json_encode($json); } ?>
Note: It is important to put this on a FAST server otherwise your webpage might hang when loading, especially if you are using the a doc-ready syntax for javascript.
Have improvements? Post them below.
Very true. Do you have an example of the best way to check the real remote address in php?
Remember to double-check that $_SERVER[‘REMOTE_ADDR’] honours X-forwarded-for headers or you’ll end up logging the wrong ip address for users behind proxies (including your own if you are using load-balancing reverse proxies)