Roshan Rathod
How can we get the IP address of the client?
By Roshan Rathod in PHP on Aug 16 2020
  • Rajanikant Hawaldar
    Sep, 2020 27

    to get the correct IP address of the user

    1. function getUserIpAddr(){
    2. if(!empty($_SERVER['HTTP_CLIENT_IP'])){
    3. //ip from share internet
    4. $ip = $_SERVER['HTTP_CLIENT_IP'];
    5. }elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
    6. //ip pass from proxy
    7. $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    8. }else{
    9. $ip = $_SERVER['REMOTE_ADDR'];
    10. }
    11. return $ip;
    12. }
    13. echo 'User Real IP - '.getUserIpAddr();

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS