Get IP Address

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
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Get IP Address

Post by thomas777neo »

Hi All

I am trying to get the ip address for my machine (I am the server). I have tried this:

Code: Select all

$ip = $REMOTE_ADDR;
Which returns 127.0.0.1, I am trying to get my machines ip of 192.x.x.x. How would I go about doing this?
AlexB
Forum Newbie
Posts: 6
Joined: Mon Apr 18, 2005 5:36 am
Location: Peterborough, UK

Post by AlexB »

I've always used this.

Code: Select all

$ip = $_SERVERї&quote;REMOTE_ADDR&quote;];
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Post by thomas777neo »

That does the same thing, it outputs 127.0.0.1.

I need the "real" ip address of my machine, not the php configuration.
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

Post by cheatboy00 »

well if your on a windows machine you can get your local lan ip by going into the command prompt and entering in "ipconfig" without the quotes... and it'll give you your address

though if your looking for a php function or something that will get someone elses lan ip I'm not sure you can do that.
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

not quite sure if this is what you are trying to get at, but ....

if you mean you are running the server and browser on the same machine, and you want to get the real IP address of the browser, when you enter the url dont use 127.0.0.1 or localhost use your actual 192.x.x.x IP address. That should return the address you are looking for.
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Post by thomas777neo »

That's almost embarrassing :oops: . Thanks for that !!!
Post Reply