Monday, May 13, 2013

Explain with code how to get a user's IP address


Identifying the IP address is a very important requirement, using which the visitor’s details could be persisted.
 For certain security considerations, IP address can be stored, if at all they purchase or reorder items, or to know about the geographical location of the visitor.
The following code snippet is used for finding IP address-
$ipAddress=@$REMOTE_ADDR;
echo "<b>IP Address= $ipAddress</b>";
If the register_global is off in php.ini file, then the following script is to be used.
$ipAddress=$_SERVER['REMOTE_ADDR'];

No comments:

Post a Comment