5 Replies - 1011 Views - Last Post: 20 February 2011 - 08:37 AM Rate Topic: -----

#1 LiDoNg_9_0  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 159
  • Joined: 03-September 09

Getting Your IP Address (You are a client)

Posted 16 February 2011 - 03:28 AM

Question... I think im having a problem with this. I try to write a code that will get my current IP address but im not sure if this is write.

<?php
echo getRealIpAddr();

function getRealIpAddr()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
    {
      $ip=$_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
    {
      $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
      $ip=$_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}
?>



i try it in different unit but the result is the same. am i doing ryt about this.. Im confused.. I need help.

Is This A Good Question/Topic? 0
  • +

Replies To: Getting Your IP Address (You are a client)

#2 chinchang  Icon User is offline

  • Indie Game Developer
  • member icon

Reputation: 192
  • View blog
  • Posts: 725
  • Joined: 22-December 08

Re: Getting Your IP Address (You are a client)

Posted 16 February 2011 - 04:43 AM

Is it working or not ?
Was This Post Helpful? 0
  • +
  • -

#3 VolcomMky  Icon User is offline

  • D.I.C Regular

Reputation: 74
  • View blog
  • Posts: 315
  • Joined: 13-May 09

Re: Getting Your IP Address (You are a client)

Posted 16 February 2011 - 08:21 AM

It would return the same IP address from all computers on the same network because they all use the same External IP Address, just different Internal IP Address

Websites read the External
Was This Post Helpful? 0
  • +
  • -

#4 LiDoNg_9_0  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 159
  • Joined: 03-September 09

Re: Getting Your IP Address (You are a client)

Posted 19 February 2011 - 09:12 PM

so is there any way to get the internal IP address?..i plan to use this application locally.
Was This Post Helpful? 0
  • +
  • -

#5 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5234
  • View blog
  • Posts: 27,024
  • Joined: 10-May 07

Re: Getting Your IP Address (You are a client)

Posted 19 February 2011 - 09:16 PM

The PHP engine can only process what it receives. If you are on a local host, then you'll be receiving the ip address based on the local network. If you are getting traffic from the cloud of the internet, then the PHP to client process & response is going to use the external, routable ip address.

It's really a matter of how the traffic is routed. As long as everything is internal, your PHP code is going to be getting the local,internal ip address.
Was This Post Helpful? 1
  • +
  • -

#6 LiDoNg_9_0  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 159
  • Joined: 03-September 09

Re: Getting Your IP Address (You are a client)

Posted 20 February 2011 - 08:37 AM

i see.. so when i try using it locally, it works. i can now get the Internal IP Address such as 192.168.66.123... thanks for the help guys.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1