Getting IP address from user

General discussions related to php

Moderators: macek, egami, gesf

sc
New php-forum User
New php-forum User
Posts: 2
Joined: Wed Feb 05, 2003 5:29 am

Getting IP address from user

Postby sc » Wed Feb 05, 2003 5:39 am

Hi!

I'm new to PHP. I made a small survey form, a HTML page that submits a form to a PHP script, and I want to get the user's IP address, but the function GetHostByName ($REMOTE_ADDR) is returning the server's IP address!
Could someone help me?
Thanks in advance!

Sergio

User avatar
Redcircle
Moderator
Moderator
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Postby Redcircle » Wed Feb 05, 2003 4:28 pm

The reason it is returning the ip address is because that is what the function does... returns the ip address. If you want the actual hostname you need to use gethostbyaddr()

sc
New php-forum User
New php-forum User
Posts: 2
Joined: Wed Feb 05, 2003 5:29 am

Postby sc » Wed Feb 05, 2003 6:16 pm

Redcircle wrote:The reason it is returning the ip address is because that is what the function does... returns the ip address. If you want the actual hostname you need to use gethostbyaddr()



No, I don't want the hostname, I *want* the IP address. But I'm getting the IP address of the machine that is running PHP/MySQL (the server), not the client's IP address (that I want).

I need to get the IP address of the user accessing my survey form, but I don't know what is happening. The function GetHostByName ($REMOTE_ADDR) is returning the local server's IP, not the remote address.

Best regards,

Sergio

User avatar
WiZARD
Moderator
Moderator
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Postby WiZARD » Wed Feb 05, 2003 11:10 pm

Code: Select all

$r_hostname = gethostbyaddr($REMOTE_ADDR);
if ($REMOTE_ADDR == "$r_hostname") {
    ....
}

greg
New php-forum User
New php-forum User
Posts: 11
Joined: Wed Nov 13, 2002 6:56 am

Postby greg » Fri Feb 07, 2003 8:57 pm

I simply use:

$ipaddress = getenv("REMOTE_ADDR");

and then echo it out or store it in a database or whatever.

[/code]

User avatar
WiZARD
Moderator
Moderator
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Postby WiZARD » Sat Feb 08, 2003 2:57 am

greg wrote:I simply use:
$ipaddress = getenv("REMOTE_ADDR");
and then echo it out or store it in a database or whatever.

In some situation than used virtual host or dynamic IP you get not correct IP or not get IP actually :?


Return to “PHP General”

Who is online

Users browsing this forum: Google [Bot] and 1 guest