Posted By

level09 on 03/21/10


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

pster
BrianCoyDesign


Get IP Address


 / Published in: PHP
 

  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  

Comments

RSS Icon Subscribe to comments
Posted By: Vordreller on March 21, 2010

Why the last $ip = "" ?

If nothing was done to the variable, then it should still have its original value, which is the same that is being entered at the end. There's no need for it, since it will only be executed when non of the previous if-statements worked.

Posted By: level09 on August 2, 2010

it helps keeping the return type consistent ( string) , so it'll return empty string instead of NULL

You need to login to post a comment.