Get IP address in PHP

/ Published in: PHP
Save to your folder(s)

How to get the ip address of the user.

Copy this code and paste it in your HTML
  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


RSS Icon Subscribe to comments

You need to login to post a comment.