URL to IP conversion

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Zanne
Forum Newbie
Posts: 15
Joined: Mon Feb 04, 2008 3:38 pm

URL to IP conversion

Post by Zanne »

Is there a way I can convert a url to an IP?

Ex:
I enter:
http://www.google.com

Script returns:
64.233.161.104

Thanks,

Zanne
User avatar
arjan.top
Forum Contributor
Posts: 305
Joined: Sun Oct 14, 2007 4:36 am
Location: Hoče, Slovenia

Re: URL to IP conversion

Post by arjan.top »

function gethostbyname()

http://si2.php.net/gethostbyname
Zanne
Forum Newbie
Posts: 15
Joined: Mon Feb 04, 2008 3:38 pm

Re: URL to IP conversion

Post by Zanne »

Thank you once again. The code works fine =)
mhonnphp
Forum Commoner
Posts: 37
Joined: Fri Oct 12, 2007 11:29 pm
Location: Philippines
Contact:

Re: URL to IP conversion

Post by mhonnphp »

how about the visitors IP?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: URL to IP conversion

Post by Christopher »

$_SERVER["REMOTE_ADDR"]
(#10850)
mhonnphp
Forum Commoner
Posts: 37
Joined: Fri Oct 12, 2007 11:29 pm
Location: Philippines
Contact:

Re: URL to IP conversion

Post by mhonnphp »

arborint wrote:$_SERVER["REMOTE_ADDR"]
arborint thanks for the reply.
but why it is different with the actual Visitors IP?
I echo $_SERVER["REMOTE_ADDR"] the result is xxx.x.x.x
example 123.0.0.0 but the actual Visitor IP is 192.168.xxx.xxx
is this accurate? and Please explain thanks.
Zanne
Forum Newbie
Posts: 15
Joined: Mon Feb 04, 2008 3:38 pm

Re: URL to IP conversion

Post by Zanne »

mhonnphp wrote:
arborint wrote:$_SERVER["REMOTE_ADDR"]
arborint thanks for the reply.
but why it is different with the actual Visitors IP?
I echo $_SERVER["REMOTE_ADDR"] the result is xxx.x.x.x
example 123.0.0.0 but the actual Visitor IP is 192.168.xxx.xxx
is this accurate? and Please explain thanks.
The 192.168.xxx.xxx is the network IP address assigned to the computer. However, what the server sees is the DNS address. to obtain the actual Visitor's IP address, try going to this link: http://www.whatsmyrealip.com

That link will tell you your actuall IP address the server will see and recognize.
mhonnphp
Forum Commoner
Posts: 37
Joined: Fri Oct 12, 2007 11:29 pm
Location: Philippines
Contact:

Re: URL to IP conversion

Post by mhonnphp »

Zanne wrote:
mhonnphp wrote:
arborint wrote:$_SERVER["REMOTE_ADDR"]
arborint thanks for the reply.
but why it is different with the actual Visitors IP?
I echo $_SERVER["REMOTE_ADDR"] the result is xxx.x.x.x
example 123.0.0.0 but the actual Visitor IP is 192.168.xxx.xxx
is this accurate? and Please explain thanks.
The 192.168.xxx.xxx is the network IP address assigned to the computer. However, what the server sees is the DNS address. to obtain the actual Visitor's IP address, try going to this link: http://www.whatsmyrealip.com

That link will tell you your actuall IP address the server will see and recognize.
Ah ok, then how can I get the real IP?
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: URL to IP conversion

Post by Kieran Huggins »

You can't - if you're on a network with a router then your IP is masked. It doesn't really matter though, because your "real IP" only means something on your local network anyway.
Post Reply