Loading Image

Almost there...

Loading Image

Loading...

Get users IP Address

This PHP function will allow you to get the current users IP address.
24 January 2017 - 11:00
Downloads: 136
Category: PHP
Get users IP Address
Overview

This PHP function will allow you to get the current users IP address.

PHP Code:
<?php
function get_ipaddress(){
    //GET IP ADDRESS
    if ($_SERVER['HTTP_CLIENT_IP']){
      $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
    }elseif($_SERVER['HTTP_X_FORWARDED_FOR']){
      $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
    }elseif($_SERVER['HTTP_X_FORWARDED']){
      $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
    }else if($_SERVER['HTTP_FORWARDED_FOR']){
      $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
    }else if($_SERVER['HTTP_FORWARDED']){
      $ipaddress = $_SERVER['HTTP_FORWARDED'];
    }else if($_SERVER['REMOTE_ADDR']){
      $ipaddress = $_SERVER['REMOTE_ADDR'];
    }else{
      $ipaddress = '';
    }

    return $ipaddress;    
}

//CALL get_ipaddress FUNCTION
echo get_ipaddress();
?>