that_tim_fella — 2011-06-24T09:56:24-04:00 — #1
I can easily use PHP to identify the IP of my locally running apache server - 127.0.0.1
Is it possible with PHP to find the IP of my machine - eg. 192.168.0.4 ?
starlion — 2011-06-24T10:06:29-04:00 — #2
127.0.0.1 isnt a 'real' IP per-se, it's the Localhost Feedback Loop.
By 'my machine' do you mean the server or the person connecting to that server?
that_tim_fella — 2011-06-24T10:14:51-04:00 — #3
The IP address designated by my router is currently 192.168.0.4. I'm running AMP through XAMPP on a Windows machine. Can PHP find the 192.168.04?
This is about running scripts just on my machine rather than on the web. Hope this explains things better.
starlion — 2011-06-24T11:23:57-04:00 — #4
Well there are two potential IP's to catch - the Server's IP (which should never change), and the Client's IP (which will be different for anyone who's visiting your site).
Both elements can be tracked in the $_SERVER predefined array;
that_tim_fella — 2011-06-24T11:43:27-04:00 — #5
Thanks for your help, but $_SERVER variables don't pull the information I require. Both of your suggestions produce 127.0.0.1
I suspect it's not possible for PHP to reach beyond the scope of the web server to get what I want.
logic_earth — 2011-06-24T11:56:34-04:00 — #6
$myIP = gethostbyname(trim(hostname
that_tim_fella — 2011-06-27T11:45:44-04:00 — #7
Excellent, exactly what I was looking for!
michael_morris1 — 2011-06-28T10:47:27-04:00 — #8
$SERVER['SERVERADDR'] reveals the IP the server was reached with for this session, not necessarily the IP assigned to the domain name. You can force the two to match as a security measure.