Track visitors using Google Maps

Create a table in your database, like 'visitor_map'. We will have these fields: id, ref, ip, location, longitude and latitude, execute the following code:

CREATE TABLE IF NOT EXISTS `visitor_map` ( `id` int(11) NOT NULL auto_increment, `ref` varchar(255) NOT NULL, `ip` varchar(15) NOT NULL, `location` varchar(32) NOT NULL, `longitude` float NOT NULL, `latitude` float NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;

For ease of use, we'll now create a configuration file. Create a file called config.php and insert the following, changing the constant values to suit your database setup and Google Maps API key.

define('DB_HOST', 'localhost'); // Database host define('DB_NAME', 'Database'); // Database being used define('DB_USER', 'user'); // Database user define('DB_PASS', 'password'); // Database user's password /* Your Google Maps API key */ define('API_KEY', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); function IPtoCoords($ip) { $dom = new DOMDocument(); $ipcheck = ip2long($ip); if($ipcheck == -1 || $ipcheck === false) trigger_error('Invalid IP, what are you doing? :|', E_USER_ERROR); else $uri = 'http://api.hostip.info/?ip=' . $ip; $dom->load($uri); $location = (strpos($dom->getElementsByTagName('name')->item(1)->nodeValue, 'Unknown') === false) ? $dom->getElementsByTagName('name')->item(1)->nodeValue : $dom->getElementsByTagName('countryAbbrev')->item(0)->nodeValue; if($location == 'XX') return false; else { $dom->load('http://local.yahooapis.com/MapsService/V1/geocode?appid=' . Yahoo_Key . '&location=' . $location); $longitude = $dom->getElementsByTagName('Longitude')->item(0)->nodeValue; $latitude = $dom->getElementsByTagName('Latitude')->item(0)->nodeValue; return array('location' => $location, 'longitude' => $longitude, 'latitude' => $latitude); } }

Now that we can successfully gain the visitor's location, we can use this to build our finished visitor map.

Visitors map

Now paste this code to /templates/your_skin_dir_name/main/main.tpl and index.tpl

{php} require 'config.php'; mysql_connect(DB_HOST, DB_USER, DB_PASS); mysql_select_db(DB_NAME); $ref = $_SERVER["HTTP_REFERER"]; $ip = $_SERVER['REMOTE_ADDR']; $userinfo = IPtoCoords($ip); $user = mysql_query('SELECT `location` FROM `visitor_map` WHERE `location` = '' . $userinfo['location'] . '''); if(!mysql_fetch_row($user) && $userinfo) mysql_query('INSERT INTO `visitor_map` (`ref`, `ip`, `location`, `longitude`, `latitude`) VALUES ('' . mysql_real_escape_string($ref) . '', '' . mysql_real_escape_string($ip) . '', '' . $userinfo['location'] . '', ' . $userinfo['longitude'] . ', ' . $userinfo['latitude'] . ')') or die(mysql_error()); {/php}

06.07.2009. 09:21


Comments

rupali 14.09.2009. 05:01

i am using the same code but gettng an error like the fun iptocoords is not valid

recover deleted files 04.12.2010. 10:40

Valuable info. Lucky me I found your site by accident, I bookmarked it.

StarJerk 27.12.2010. 08:29

The moment I saw your blog was like wow. Thank you for putting your effort in publishing this site.

payday loans online 29.12.2010. 11:28

Regards for all the great blog posts!

software catalog 03.01.2011. 11:03

I have many question about your post. I think u should write lot of more details. But Thanks anymore

W-Music 11.01.2011. 08:58

That is f*ckin' awesome iRealty mods . Very good and interesting article. Thanks for helpful and useful information.

laptop bags 12.01.2011. 11:44

Today I read some very interesting article. Its Ur article. Thanks

Video Poker at Caribbean Gold Casino 13.01.2011. 08:28

First of all I care for the quality of your post. That was interesting to read and helpful article. And Im lookin' forward to see your next thinks.

Google world map 01.02.2011. 10:14

Good job. Useful and helpful info here. Thanks

Gologan 09.02.2011. 13:03

and I have been looking for such information

russian brides dating 14.02.2011. 15:39

That's useful informative and f*ckin awesome. Great job

free online dating service 14.02.2011. 16:21

Im glad to see this informative article. Thanks for such helpful and useful post.

internet speed 16.02.2011. 13:01

due recently reinstalled the operating arrangement, and it took a batch of things in identical place

Duplicate Content Checker Tool 17.02.2011. 16:28

This is the right blog for anyone who wants to find out about this subject.

domain who is 22.02.2011. 06:30

Darn, I enjoy your selection of layout, it truly is unique in my opinion

check my ip address 24.02.2011. 18:02

It does seem that everybody is into this kind of stuff lately. Appriciate you shedding light into this matter. Keep it up.

ip address locator 24.02.2011. 18:16

I have been examinating out some of your articles and i must say clever stuff. I will surely bookmark your website.

russian marriage agency 25.02.2011. 09:26

Get Started on Your Own Weight Loss and Health Goals right away with these Simple and Effective Healthy Meal Plans.

buy laptop 02.03.2011. 06:46

great knowledge of carries bettered very much.

Cell phone reviews 03.03.2011. 15:01

i was thinking the other day that there must be a technique with a view my kids to training at digs what they learn in class

final cut pro 7 serial number 04.03.2011. 16:31

i'm simply 15, and i don't know much about the rates and if they're expected to flatten, keep climbing,

flip camcorder review 09.03.2011. 14:12

Have you thought about adding some differing opinions to your article

cheap Kamagra Oral Jelly 06.04.2011. 14:05

Very Nice website. I just finished mine and i was looking for some design ideas and you gave me a few. May i ask you whether you developed the website by youself

buy adobe acrobat professional 13.04.2011. 10:53

I appreciate the info!

cheap software 14.04.2011. 09:33

i love your website. i'm gonna post a link on my facebook page!

windows 7 cheap 14.04.2011. 09:47

i dont think i'd have the time or even drive to maintain it up to date as you do once again many thanks as well as all the best

Easy way to buy viagra 14.04.2011. 10:14

thank you as one more great article. where else could anybody reach that agreeable of knowledge inside that a faultless convention of writing

order cigarettes Canada 14.04.2011. 10:17

Keep posting stuff like this i really like it

viagra online 14.04.2011. 10:30

very newsworthy topic , outstanding post.

viagra 14.04.2011. 10:47

Thank You For This Post, was added to my bookmarks.

<< First < Previous [1 / 20] Next > Last >>

Write a comment

* = required field

:

:

:


6 + 4 =