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

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

The users IP address can be returned by specifying the host name as aparameter in gethostbyname(“hostname”) method.

Example:
<?php
   $ip = gethostbyname('www.sample.com');
   echo $ip;
?>

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'];
PHP - Explain with code how to generate a random number from php.
Explain with code how to generate a random number from php - The function rand() can be used to generate random number....
PHP - Explain about Type Juggling in php with an example
Explain about Type Juggling in php with an example - The ternary conditional operator is of the form.....
PHP - Difference between Reply-to and Return-path in the headers of a mail function.
Difference between Reply-to and Return-path in the headers of a mail function - Reply-to is the address where the email needs to be delivered...
Post your comment