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
Switch to threaded view of this topic Create a new topic Submit Reply
ip address of client [message #173236] Tue, 29 March 2011 05:46 Go to next message
suresh is currently offline  suresh
Messages: 5
Registered: March 2011
Karma: 0
Junior Member
Hi
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?

<?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;

thanks
suresh
Re: ip address of client [message #173237 is a reply to message #173236] Tue, 29 March 2011 06:47 Go to previous messageGo to next message
richard is currently offline  richard   
Messages: 213
Registered: June 2013
Karma: 0
Senior Member
On Mon, 28 Mar 2011 22:46:48 -0700 (PDT), suresh wrote:

> Hi
> 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?
>
> <?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;
>
> thanks
> suresh

echo "welcome " $ip;
echo "welcome ".$ip;

only one echo per physical line.
Re: ip address of client [message #173238 is a reply to message #173236] Tue, 29 March 2011 06:51 Go to previous messageGo to next message
gordonb.oas0f is currently offline  gordonb.oas0f
Messages: 1
Registered: March 2011
Karma: 0
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;
Re: ip address of client [message #173241 is a reply to message #173237] Tue, 29 March 2011 10:47 Go to previous messageGo to next message
Beauregard T. Shagnas is currently offline  Beauregard T. Shagnas
Messages: 154
Registered: September 2010
Karma: 0
Senior Member
richard the sto0pid wrote:

> On Mon, 28 Mar 2011 22:46:48 -0700 (PDT), suresh wrote:
>
>> Hi
>> 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?
>>
>> <?php
>> [snip code to only what RtS is replying to]
>> echo "Welcome "; echo $ip;
>
> echo "welcome " $ip; <--- wrong
> echo "welcome ".$ip; <--- will work, as is concatenated
>
> only one echo per physical line.

Incorrect and not necessary. His line: echo "Welcome "; echo $ip;
is perfectly legitimate, having the proper terminator ";" after the
first echo. A newline is not required between commands.

--
-bts
-In a broadband world, you are just a dialup
Re: ip address of client [message #173247 is a reply to message #173241] Tue, 29 March 2011 21:08 Go to previous messageGo to next message
richard is currently offline  richard   
Messages: 213
Registered: June 2013
Karma: 0
Senior Member
On Tue, 29 Mar 2011 06:47:45 -0400, Beauregard T. Shagnasty wrote:

> richard the sto0pid wrote:
>
>> On Mon, 28 Mar 2011 22:46:48 -0700 (PDT), suresh wrote:
>>
>>> Hi
>>> 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?
>>>
>>> <?php
>>> [snip code to only what RtS is replying to]
>>> echo "Welcome "; echo $ip;
>>
>> echo "welcome " $ip; <--- wrong
>> echo "welcome ".$ip; <--- will work, as is concatenated
>>
>> only one echo per physical line.
>
> Incorrect and not necessary. His line: echo "Welcome "; echo $ip;
> is perfectly legitimate, having the proper terminator ";" after the
> first echo. A newline is not required between commands.

while it may be correct, it serves no purpose.
Proper use of string manipulation will not confuse the server.
Re: ip address of client [message #173248 is a reply to message #173247] Tue, 29 March 2011 21:12 Go to previous messageGo to next message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma: 0
Senior Member
.oO(richard)

> On Tue, 29 Mar 2011 06:47:45 -0400, Beauregard T. Shagnasty wrote:
>
>> Incorrect and not necessary. His line: echo "Welcome "; echo $ip;
>> is perfectly legitimate, having the proper terminator ";" after the
>> first echo. A newline is not required between commands.
>
> while it may be correct, it serves no purpose.
> Proper use of string manipulation will not confuse the server.

This is not about string manipulation at all, but simply about code
formatting preferences.

Micha
Re: ip address of client [message #173250 is a reply to message #173247] Tue, 29 March 2011 23:42 Go to previous message
Beauregard T. Shagnas is currently offline  Beauregard T. Shagnas
Messages: 154
Registered: September 2010
Karma: 0
Senior Member
richard the sto0pid wrote:

> Beauregard T. Shagnasty wrote:
>> richard the sto0pid wrote:
>>> suresh wrote:
>>>> 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?
>>>>
>>>> <?php
>>>> [snip code to only what RtS is replying to]
>>>> echo "Welcome "; echo $ip;
>>>
>>> echo "welcome " $ip; <--- wrong
>>> echo "welcome ".$ip; <--- will work, as is concatenated
>>>
>>> only one echo per physical line.
>>
>> Incorrect and not necessary. His line: echo "Welcome "; echo $ip; is
>> perfectly legitimate, having the proper terminator ";" after the
>> first echo. A newline is not required between commands.
>
> while it may be correct, it serves no purpose.
> Proper use of string manipulation will not confuse the server.

What kind of a backpedaling answer is that? Did you not understand my
response?

--
-bts
-In a broadband world, you are just a dialup
  Switch to threaded view of this topic Create a new topic Submit Reply
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: Sat Nov 23 21:21:43 GMT 2024

Total time taken to generate the page: 0.02169 seconds