When using either $_SERVER['REMOTE_ADDR']; or @$REMOTE_ADDR;, I understand this retrieves the IP of the visitor of the page.
I'm just wondering, if I'm on a LAN network and I visit the page on both computers, will they have different IP's when based on the return value of
$_SERVER['REMOTE_ADDR']; or @$REMOTE_ADDR ?
Does each computer have a unique IP no matter what?
Retrieving IP with PHP
Moderator: General Moderators
Re: Retrieving IP with PHP
No. REMOTE_ADDR will get you the public-facing IP address. When you're behind a router you'll get the router's address.
And no, you can't get the address of the machine behind it.
And no, you can't get the address of the machine behind it.
Re: Retrieving IP with PHP
Thanks.
Re: Retrieving IP with PHP
I was actually looking for something of the same nature the other day for an internal site I am building and wanted to capture subnets etc...
I have not tried it yet but will be doing so later...
here is the URL
http://www.cyberciti.biz/faq/php-howto- ... erbrowser/
I have not tried it yet but will be doing so later...
here is the URL
http://www.cyberciti.biz/faq/php-howto- ... erbrowser/
Geert March 22, 2009 at 1:38 pm
They are all behind the same proxy-server. In that case $_SERVER['REMOTE_ADDR'] provides you with the ip-address of the proxy-server.
This function will determine the real ip-adress:
Code: Select all
function ipCheck() { if (getenv('HTTP_CLIENT_IP')) { $ip = getenv('HTTP_CLIENT_IP'); } elseif (getenv('HTTP_X_FORWARDED_FOR')) { $ip = getenv('HTTP_X_FORWARDED_FOR'); } elseif (getenv('HTTP_X_FORWARDED')) { $ip = getenv('HTTP_X_FORWARDED'); } elseif (getenv('HTTP_FORWARDED_FOR')) { $ip = getenv('HTTP_FORWARDED_FOR'); } elseif (getenv('HTTP_FORWARDED')) { $ip = getenv('HTTP_FORWARDED'); } else { $ip = $_SERVER['REMOTE_ADDR']; } return $ip; }
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Retrieving IP with PHP
That function will only reveal the visitors ip (behind a proxy) if the proxy is not transparent -- which most are. Simply put, when a user is behind a proxy, it is usually not possible to get their real ip address.Architek wrote:I was actually looking for something of the same nature the other day for an internal site I am building and wanted to capture subnets etc...
I have not tried it yet but will be doing so later...
here is the URL
http://www.cyberciti.biz/faq/php-howto- ... erbrowser/
Geert March 22, 2009 at 1:38 pm
They are all behind the same proxy-server. In that case $_SERVER['REMOTE_ADDR'] provides you with the ip-address of the proxy-server.
This function will determine the real ip-adress:
Code: Select all
function ipCheck() { if (getenv('HTTP_CLIENT_IP')) { $ip = getenv('HTTP_CLIENT_IP'); } elseif (getenv('HTTP_X_FORWARDED_FOR')) { $ip = getenv('HTTP_X_FORWARDED_FOR'); } elseif (getenv('HTTP_X_FORWARDED')) { $ip = getenv('HTTP_X_FORWARDED'); } elseif (getenv('HTTP_FORWARDED_FOR')) { $ip = getenv('HTTP_FORWARDED_FOR'); } elseif (getenv('HTTP_FORWARDED')) { $ip = getenv('HTTP_FORWARDED'); } else { $ip = $_SERVER['REMOTE_ADDR']; } return $ip; }