Posted By

kendsnyder on 01/18/11


Tagged

ip ipAddress HTTPCLIENTIP HTTPXFORWARDEDFOR REMOTEADDR


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

silverskymedia
pytheas
spaceploitator


Get IP Address


 / Published in: PHP
 

  1. function getIpAddress() {
  2. // based on
  3. // http://stackoverflow.com/questions/527638/getting-the-client-ip-address-remote-addr-http-x-forwarded-for-what-else-could
  4. // http://www.grantburton.com/?p=97
  5. $check = array(
  6. 'HTTP_CLIENT_IP','HTTP_X_FORWARDED_FOR','HTTP_X_FORWARDED',
  7. 'HTTP_X_CLUSTER_CLIENT_IP','HTTP_FORWARDED_FOR','HTTP_FORWARDED','REMOTE_ADDR',
  8. );
  9. $ip = '0.0.0.0';
  10. foreach ($check as $key) {
  11. if (isset($_SERVER[$key])) {
  12. list ($ip) = explode(',', $_SERVER[$key]);
  13. break;
  14. }
  15. }
  16. return $ip;
  17. }

Report this snippet  

You need to login to post a comment.