Learning to Get IP Address
Written on May 2, 2008 – 1:21 am | by Keith Neo
Getting a user’s or visitor’s IP address is very easy using PHP. Basically, there are two commands to obtain the information, as such information has already been stored in the server. These commands are either
$_SERVER['REMOTE_ADDR']
if register_global is turned on; or
@$REMOTE_ADDR
if register_global is switched off.
Below is a simple example of how to do it.
Assuming that the register_global is turned on,
<?php
$ip=$_SERVER['REMOTE_ADDR'];
echo “IP Address = $ip”;
?>
The output from the above code is as follow:
IP Address = 38.103.63.59
Simple, isn’t it?


































1 Trackback(s)