php-获取基于ip调用移动设备的国家代码

Is there any way To Detect Country code for calling on mobile of user using his/her ip address?

Actually I'm trying that for sending SMS on clients device. For Sending password recovery to their mobile if requested, For that I log their country code based on their IP at time of sign up.

But even if I've their Country saved in my DB and also IP catched by php script, I am unable to convert that information to their country code.

ex.

I've Info Like:

IP: 127.0.0.1 //Just for ex.

Country: Chile

Mobile: XX88XX99XX

Then How can I get Country code for that specific country Here in this case +056, +001 for US. For Sending SMS to that mobile number?

Is it possible in php?

If So, How?

Can Experts here please help me?

Thanks in advance.

$ip = $_SERVER['REMOTE_ADDR'];
$data = file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $ip);
$data = json_decode($data);
echo $data->geoplugin_currencyCode;

See more here: http://www.geoplugin.net/json.gp Don't use it with 127.0.0.1 or localhost because it will send 127.0.0.1. Here is an example with my IP.