Hey guys, i'm dng a website with geographic location, i want to track user's city or country with PHP, is it possible ? please help me guys.

Thanks in advanse

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..

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

commented: This need registration & this won't work for Indian based IP Addresses +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.