How to get IP address of visitor in PHP
Getting the IP address of the visitor is the simplest task in PHP.Look at the following example:
<?php
$userIP = $_SERVER["REMOTE_ADDR"];
echo $userIP;
?>
$userIP = $_SERVER["REMOTE_ADDR"];
echo $userIP;
?>
This should print something like following if you are working in wamp server or any local environment.
127.0.0.1
All the magic is done by the PHP superglobal $_SERVER.The REMOTE_ADDR is just another element of $_SERVER superglobal whcich retrieves the IP of the user computer.Note that this IP sometimes may be the IP of the LAN, the user is connected with.
0 comments:
Subscribe to:
Post Comments (Atom)
Post a Comment