I'm using PHP and MySQL. How can I query the IP address of subscribers?
Asked
Active
Viewed 65 times
-2
-
Do not use IP address for anything like authentication etc.? It is rather meaningless as some routers use the same IP address for multiple machines. This is especially true for some ISPs. Also they can be dynamically allocated. – Ed Heal Feb 26 '14 at 04:00
3 Answers
0
this will display the ip address
echo $_SERVER['REMOTE_ADDR'];
if you want to store the ip address of the users, use this
$ipaddress = echo $_SERVER['REMOTE_ADDR'];
mysql_query("insert into table set ipaddress = '$ipaddress' where userid = '$userid' ");

Ananth
- 1,520
- 3
- 15
- 28
0
function get_client_ip()
{
$ipaddress = '';
if (getenv('HTTP_CLIENT_IP'))
$ipaddress = getenv('HTTP_CLIENT_IP');
else if(getenv('HTTP_X_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_X_FORWARDED_FOR');
else if(getenv('HTTP_X_FORWARDED'))
$ipaddress = getenv('HTTP_X_FORWARDED');
else if(getenv('HTTP_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_FORWARDED_FOR');
else if(getenv('HTTP_FORWARDED'))
$ipaddress = getenv('HTTP_FORWARDED');
else if(getenv('REMOTE_ADDR'))
$ipaddress = getenv('REMOTE_ADDR');
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
Source

Virendra
- 2,560
- 3
- 23
- 37

Amarnath Balasubramanian
- 9,300
- 8
- 34
- 62