Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

How to get IP address in a Nokia Asha Web App

From Wiki
Jump to: navigation, search

This article explains how one can find out public IP address of your device and Web App proxy server. Solution uses a simple PHP script that returns these values to your web app in a JSON format.

Article Metadata
Platform(s): Series 40
Device(s): All having Nokia Browser
Created: isalento (30 Dec 2011)
Last edited: hamishwillee (09 May 2013)



About IP addresses

First thing to note, is that public IP address obtained with this solution, is not the real private IP address of your device. In most cases you will see outbound IP address of proxy or router in your network.

Nokia Asha Web Apps Proxy server appends IP address of the client, connecting Web App Proxy, to HTTP_X_FORWARDED_FOR header. HTTP_X_FORWARDED_FOR header is commonly used for this purpose by other proxies as well, thus its value might be comma separated list of IP addresses.

For example, when you are using Nokia Browser to open a Web App using WLAN connection, you will probably only see router’s IP address in HTTP_X_FORWARDED_FOR header. Same practice applies to 2G/3G connections. There it is likely that you will see IP address of your operator’s router. When web app proxy is used, REMOTE_ADDR holds the IP address of the proxy. If you are running this script in a local preview mode in Web App simulator, Web App proxy is not used and REMOTE_ADDR is your computer’s / router’s IP address.


Getting the public IP address requires a query to be made to a server. As a response to this query IP address information is returned in a JSON format.

function checkIp(){
req = new XMLHttpRequest();
var url = "";"GET", url , true);
req.onreadystatechange = function(){
if(req.readyState == 4) {
if (req.status == 200){
var ip = eval('(' + req.responseText + ')');
if(ip.HTTP_X_FORWARDED_FOR != ""){
log("Web App proxy server address: "+ ip.REMOTE_ADDR);
log("Public IP address(s): " + ip.HTTP_X_FORWARDED_FOR);
log("Public IP address(s):" + ip.REMOTE_ADDR);
log("Error:" + req.status+ " "+ req.statusText);
function log(text) {
document.body.innerHTML += text+"<br>";

PHP script

Following short PHP script acts as a backend for our IP API.

//Gets the IP addresses
$server_ip = getenv("REMOTE_ADDR") ;
$device_ip = getenv("HTTP_X_FORWARDED_FOR");
echo '{ "REMOTE_ADDR": "' . $server_ip . '","HTTP_X_FORWARDED_FOR":"'. $device_ip . '"}';
This page was last modified on 9 May 2013, at 10:49.
83 page views in the last 30 days.