Posted By

priteshloke on 12/29/11


Tagged

utility


Versions (?)

get ip


 / Published in: PHP
 

getip server and command code

  1. function getip() {
  2. if ($_SERVER) {
  3. if ( isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] ) {
  4. $realip = $_SERVER["HTTP_X_FORWARDED_FOR"];
  5. } elseif ( isset($_SERVER['HTTP_CLIENT_IP']) && $_SERVER["HTTP_CLIENT_IP"] ) {
  6. $realip = $_SERVER["HTTP_CLIENT_IP"];
  7. } else {
  8. $realip = $_SERVER["REMOTE_ADDR"];
  9. }
  10. } else {
  11. if ( getenv('HTTP_X_FORWARDED_FOR') ) {
  12. $realip = getenv('HTTP_X_FORWARDED_FOR');
  13. } elseif ( getenv('HTTP_CLIENT_IP') ) {
  14. $realip = getenv('HTTP_CLIENT_IP');
  15. } else {
  16. $realip = getenv('REMOTE_ADDR');
  17. }
  18. }
  19. return $realip;
  20. }

Report this snippet  

You need to login to post a comment.