Posts marked with "Geographic" in tags

Finding Client’s IP address, Country, State, City using NetIP.de api in PHP

If you want to get client’s IP address you will use $_SERVER[‘REMOTE_ADDR’] function in PHP.
But you will not get the real IP address of the client. To get the real IP address You can use the method I used.
Also With this method you can also find the City, State, Country client’s in.
The code is pretty simple. With the help of NetIP.de it was pretty easy.

$response=@file_get_contents(‘http://www.netip.de’);if (empty($response)){throw new InvalidArgumentException("Error contacting Geo-IP-Server");}$patterns=array();$patterns["state"] = ‘#State/Region: (.*?);$patterns["IP"] = ‘#IP: (.*?) #i’;$patterns["country"] = ‘#Country: (.*?) #i’;$patterns["city"] = ‘#City: (.*?) $pattern){$ipInfo[$key] = preg_match($pattern,$response,$value) && !empty($value[1]) ? $value[1] : ‘not found’;} $uct=$ipInfo["state"];$uip=$ipInfo["IP"];$uci=$ipInfo["city"];$ipInfo=explode(‘-‘,$ipInfo["country"]);$ucs=$ipInfo[0];$uco=$ipInfo[1];

... [READ MORE]

Follow/Subscribe

Telegram 

Mastodon  Twitter

GitHub GitLab

Subdomains

Demos  Lab

Past

This blog was once on WordPress. Now a static site. See source code on

GitLab