Posted By

ginoplusio on 12/03/09


Tagged

ip HTTPCLIENTIP HTTPXFORWARDEDFOR REMOTEADDR


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

StrawMan


Get IP address in PHP


 / Published in: PHP
 

URL: http://www.barattalo.it/2009/12/03/how-many-users-are-connected/

How to get the ip address of the user.

  1. function getIP() {
  2. $ip="";
  3. if (getenv("HTTP_CLIENT_IP")) $ip = getenv("HTTP_CLIENT_IP");
  4. else if(getenv("HTTP_X_FORWARDED_FOR")) $ip = getenv("HTTP_X_FORWARDED_FOR");
  5. else if(getenv("REMOTE_ADDR")) $ip = getenv("REMOTE_ADDR");
  6. else $ip = "";
  7. return $ip;
  8. }

Report this snippet  

You need to login to post a comment.