I would like to get the visitor IP by using any online service like https://www.ipstack.com or https://www.ipify.org/ but the problem when I use PHP code it returns the server IP. I understand that because the code runs in the server and its return the server IP, But how could I get the visitor IP? I dont want to use REMOTE_ADDR or so.
I tried getting the visitor IP by using getJSON but the problem then how to pass the data to PHP code and use it there.
======UPDATE======
Other pages not solving the issue so please dont add links..
The issue I want to use this api: http://api.ipstack.com/check?access_key=xxxxx&output=json
Here we will get the data as JSON.. But how to pass the data to PHP?
==========UPDATE========== The code I am using right now to get the visitor IP..
foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key) {
if (array_key_exists($key, $_SERVER) === true) {
foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) {
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false) {
return $ip;
}
}
}
}
Thanks