FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » ip address of client
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: ip address of client [message #173238 is a reply to message #173236] Tue, 29 March 2011 06:51 Go to previous message
gordonb.oas0f is currently offline  gordonb.oas0f
Messages: 1
Registered: March 2011
Karma:
Junior Member
> I was using the following script to get ip address of client, but I
> get Welcom ::1 from the following script. How to get the real ip
> address?

If someone is using a proxy on their local machine (perhaps to speed
up network access), that may *BE* the real IP (v6) address (localhost)
as defined by your function. If more than one of
$_SERVER['HTTP_CLIENT_IP']
$_SERVER['HTTP_X_FORWARDED_FOR']
and $_SERVER['REMOTE_ADDR']

are defined, it is not always obvious which one is "real". The
first two can be IP addresses in someone's local network that are
not reachable from the outside. The first two can also be faked.
I recommend logging all three.


> <?php
> 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;
> }
> $ip = getRealIpAddr();
> echo "Welcome "; echo $ip;
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Very strange behaviour of imageftbbox()?
Next Topic: CLP - ON TOPIC! - Need PHP form email help, Please!
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 00:46:53 GMT 2024

Total time taken to generate the page: 0.04185 seconds