Translating url

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
yoger
Forum Newbie
Posts: 3
Joined: Fri Aug 28, 2009 1:31 pm

Translating url

Post by yoger »

Hello everybody!
I need to know something about php.
So, I'm gathering my server URL by command $_SERVER['HTTP_HOST'] but it returns somethink like myserver.com just string, but I need to translate it to numarical IP address like 127.0.0.1.
Is there in PHP any function that can help me with that?
sousousou
Forum Commoner
Posts: 29
Joined: Fri Aug 28, 2009 1:10 pm

Re: Translating url

Post by sousousou »

$_server[’SERVER_ADDR’] ?
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Translating url

Post by Eran »

yoger
Forum Newbie
Posts: 3
Joined: Fri Aug 28, 2009 1:31 pm

Re: Translating url

Post by yoger »

That would be too easy, SERVER_ADDR returns my routers IP, which is 192.168.1.10, when I need my IP (which is atm 83.21.154.63). Any other ideas?
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Translating url

Post by Eran »

you need to know your external IP? your computer can't tell you this. You need to speak with router somehow, which would probably involve invoking a shell command.
sousousou
Forum Commoner
Posts: 29
Joined: Fri Aug 28, 2009 1:10 pm

Re: Translating url

Post by sousousou »

I'm not very advanced, but maybe try something with gethostbyname() ?
yoger
Forum Newbie
Posts: 3
Joined: Fri Aug 28, 2009 1:31 pm

Re: Translating url

Post by yoger »

No idea how but it works :D
Thanks for this pal!
sousousou
Forum Commoner
Posts: 29
Joined: Fri Aug 28, 2009 1:10 pm

Re: Translating url

Post by sousousou »

yoger wrote:No idea how but it works :D
Thanks for this pal!
:dubious: First time I've ever solved someone else's PHP problem :dubious:
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Translating url

Post by John Cartwright »

sousousou wrote:
yoger wrote:No idea how but it works :D
Thanks for this pal!
:dubious: First time I've ever solved someone else's PHP problem :dubious:
:drunk:
Post Reply