4
Contributors
3
Replies
6
Views
5 Years
Discussion Span
Last Post by chrislim2888
0

Have a look at HTML 5 feature for GEOLOCATION... Or use IP Address to track your users in PHP...

I hope this helps you a bit..

1

Hi,

This is what I am currently using, but my script records the IP of the visitors and the members as well, so that I can show who is online with their respective country flags based on the remote address.

Since I don't know your database instructures, I will use a simple script of which you can build what you are trying to make..

First, we need to detect the IP address of the browser...

$ip = $_SERVER['REMOTE_ADDR'];

Once we know about the IP address, we can pass that on to the hostip.info API to get the flag. hostip is not 100% is sluggish during redundant query.. So, I suggests for you to store the information gathered in your own database. The API returns two letter country codes.

Second, based on the ip above we can send our query to the API for the country flag to show on the page. We can use the codes below to do just that. Here is the complete script..

$ip = $_SERVER['REMOTE_ADDR'];
echo '<IMG width="20px" height="15px" SRC="http://api.hostip.info/flag.php?ip='.$ip.'" ALT="IP Address Lookup">';

Depending on the requesting traffic from the hostifp.info, your IP and flag specific to the country of your IP should be showing on this Demo. I am using the same script above with minor modification..

Of course you can expand and extend the above codes by visiting the hostip.info API usage guides. http://www.hostip.info/use.html

Edited by veedeoo: more info added

Votes + Comments
This need registration & this won't work for Indian based IP Addresses
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.