How to get IP Address using phonegap javascript

て烟熏妆下的殇ゞ 提交于 2020-01-13 19:05:41

问题


How to get IP Address using phonegap javascript. I have to send this IP address to php page as a QueryString.

Any Suggestion ?


回答1:


Here you go:

http://simonmacdonald.blogspot.in/2012/08/so-you-wanna-write-phonegap-200-android.html

Basically, you need to use a phonegap plugin that acts as a javascript wrapper and uses a method from the native android SDK to get you the required IP address.




回答2:


Do not do any code in you Javascript ant send it to PHP page but in PHP page you can do the following function call to get the Real IP address...

function getRealIpAddr()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
    {
      $ip=$_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
    {
      $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
      $ip=$_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}


来源:https://stackoverflow.com/questions/12708330/how-to-get-ip-address-using-phonegap-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!