Does php have a function for obtaining the ip address of the machine it is running on?
Microsoft windows does the same thing using WINIPCFG.
Thanks.
Richie.
use $_SERVER['REMOTE_ADDR'] variable.
Jayant,
What I need is the IP address of the machine that php is running on, not the ip address of a visitor to the website.
'REMOTE_ADDR' The IP address from which the user is viewing the current page.
If you want to find an IP address given the host name try PHP's gethostbyname($hostname) function.
To find multiple IP address you could use the function gethostbyname1($hostname).
To get the $hostname automatically...in case you don't know:
gethostbyname($HTTP_SERVER_VARS["SERVER_NAME"])
Originally posted by richie Jayant, What I need is the IP address of the machine that php is running on, not the ip address of a visitor to the website. 'REMOTE_ADDR' The IP address from which the user is viewing the current page. Richie.
Well your question is already answered now.
This gives me a lesson, never do things when you are half awake. One tends to overlook somethings
This is a piece of code I use for test. Ciao. Michele.
<?php $myLook[BACK1]="yellow" ; echo "<table cellspacing=\"0\">" ; echo "<tr bgcolor=\"$myLook[BACK1]\"><td><h5>PHP constants</h5></td><td></td></tr>" ; echo "<td>operating system</td><td><b>".PHP_OS."</b></td></tr>" ; echo "<tr bgcolor=\"$myLook[BACK1]\"><td><h5>APACHE variables</h5></td><td></td></tr>" ; echo "<td>browser</td><td><b>".$HTTP_USER_AGENT."</b></td></tr>" ; echo "<td>server name</td><td><b>".$SERVER_NAME."</b></td></tr>" ; echo "<td>server port</td><td><b>".$SERVER_PORT."</b></td></tr>" ; echo "<td>server software</td><td><b>".$SERVER_SOFTWARE."</b></td></tr>" ; echo "<td>http host</td><td><b>".$HTTP_HOST."</b></td></tr>" ; echo "<td>http referer</td><td><b>".$HTTP_REFERER."</b></td></tr>" ; echo "<td>http connection</td><td><b>".$HTTP_CONNECTION."</b></td></tr>" ; echo "<td>http accept language</td><td><b>".$HTTP_ACCEPT_LANGUAGE."</b></td></tr>" ; echo "<td>remote address</td><td><b>".$REMOTE_ADDR."</b></td></tr>" ; echo "<td>remote port</td><td><b>".$REMOTE_PORT."</b></td></tr>" ; echo "<td>server signature</td><td><b>".$SERVER_SIGNATURE."</b></td></tr>" ; echo "<td>request URI</td><td><b>".$REQUEST_URI."</b></td></tr>" ; echo "<td>path translated</td><td><b>".$PATH_TRANSLATED."</b></td></tr>" ; echo "<td>script filename</td><td><b>".$SCRIPT_FILENAME."</b></td></tr>" ; echo "</table>"; ?>
Oops, sorry for previous post: I was missing THE POINT.
You can get the SERVER IP address using the function gethostbyname() with SERVER_NAME
Ciao. Michele.
echo "<td>server IP address</td><td><b>".gethostbyname($SERVER_NAME)."</b></td></tr>" ;
Thanks everybody for your help.
gethostbyname($SERVER_NAME) did it.