https://www.icyphoenix.com/viewtopic.php?f=28&t=3701 ----------------------------------- ieio Wed 27 Feb, 2008 08:17 Track Visitors To Your Website Using Google Maps ----------------------------------- In last week I looked for a solution since I always liked IP address geocode: i'm not a programmer, i'm a newbie but i'm curious enough to get a point so I share with you hoping it could be a starting point for some other I checked some embedding solutions but I'll report only my top 4 services [code linenumbers=false]http://www.ipligence.com/webmaps/ http://maps.amung.us/ (stilish) http://www.frappr.com/?a=basics&s=size&mvid=137440428968&origin=onsite (if visitor deeply feels itself a part of the community)[/code] my choice http://www.gvisit.com/ gvisit is really easy to use but as a free service you'll get tracked only the last 10-20 visitors (no banner insertion needed, you can donate to upgrade and get tracked more visitors) just insert your web site and in a click you'll get the code to insert -for example- in the footer (better since the page is almost loaded andthis can prevent delay with gvisit server): here's the code for IP [code linenumbers=false][/code] once the code is posted in the page you want to be tracked to, you can see IP map @ this URL http://www.gvisit.com/map.php?sid=d75f62f8766d5a46475eee769de66255 there's a way to embed this map using a JavaScript that can manage RSS map feed and create the map (could be interesting not only for this purpose, take a look http://feed2js.org/ ) but I didn't want to since I don't like to put a fixed size window in a dinamically generated web page and install script outside IP running on my main server so I only put a little left block with a static jpeg (feel free to use it) [img]http://www.icyphoenix.com/files/images/1392/map.gif[/img] [code linenumbers=false]
TITLE

[/code] I checked width&height both with ffox and ie and you'll get the right window [img]http://www.icyphoenix.com/files/images/1392/immagine.jpg[/img] OK, all is working but I'd prefer to have this service running on my own server... I started to read Google maps API docs, then I found this project and I said: WOW!! too early... Credits goes to http://frikk.tk/ that reassemble part of code taken from various documentation [quote] [b]Abstract[/b] This is a tutorial which shows how do develop your own implementation of Google Maps using PHP, MySQL, a little html/javascript, and a Google Api Key. This tutorial shows how to make your own Geographical Visitor Map, which I am using on [url=http://frikk.tk/?gmap]my own website (Caution: For some reason that link crashes Internet Explorer). I also have a [url=http://frikk.tk/files/php/google_maps/gmap.php]running demo which is structured exactly as this tutorial is set up, which does not crash IE. [b]The purpose[/b] Everyone knows about Google Maps. They revolutionized the mapping world with the integration of satelite imagery, directions, and standard atlas-style maps, which display road information, parks, cities, states, etc. In the internet world, Google Maps was perhaps the first major website to feature a beautiful robost AJAX based interface. This meant you could scroll around the map, zoom in and out, as well as switch between map styles - all without refreshing the page. Now adays, AJAX is all the rage. "Web 2.0" is the new buzzword, and everyone (myself included) is racing to come up with the coolest AJAX-enabled projects. How long will the fad last? Who cares! At least we all have something else to complain about to the standards-nazis. Anyways, here I will show you how to build an interface to Google Maps which will show you the geographical location of your website visitors. We will be using some standard web tools, including PHP, MySQL, Javascript, and of course XHTML/CSS. [b]Zip File[/b] You can download a zip file to follow a long with. It is meant to be used as reference, and may not completely work on its own. Download from attached This includes: * gmap.php - main gmap file * netgeo.php - IP 2 GPS lookup * browser.php - Browser / OS info * map_ip.sql - SQL Table Syntax [b]Before We Start[/b] There are a few things you need to have set up before we start: * First, a [url=http://www.google.com/apis/maps/signup.html]Google API Key * A MySQL Database for storing the Geographical Information * A working web server which has PHP and a MySQL database The Google API Key is a very simple thing to retrieve, just go to the website and sign up. It seriously takes less than 2 minutes. We need this in order to connect to the Google Maps server. The only limitation is that you have something like 5000 hits per day limit, and you can only use each API on one domain that you specify upon sign up. I would also suggest briefly reading up on the [url=http://www.google.com/apis/maps/documentation/]Google Maps API Documentation. Although this is not required, it will give you an understanding of what we will be doing here today. It is a very easy read, and if you have a little bit of programming and/or javascript experience, it will especially be a breeze. [b]The Structure of it all![/b] There are several pieces to the project we are doing. * A PHP function to convert and store a visitor's Longitude and Latiude from their Ip address (as well as any other information, such as Operating System or Web Browser) * A PHP function for determining the Browser and OS of the visitor. This is a nice feature to add some "spice" to your map * A PHP function to output the necessary Javascript commands to tell the Google Map what to display according the the Longitude/Latidude information we have * The actual Google Map page that will display the blips where the visitors are from [b]The MySQL Database Set Up[/b] We need to create a database to store all of the user information into. You can use a tool such as PHPMyAdmin, or the MySQL Command line. You will need to have an existing database, of course. Once you have it created, go into PHPMyAdmin or the command line, and use the following SQL syntax to create the necessary table: [code linenumbers=false]-- -- Table structure for table `map_ip` -- CREATE TABLE IF NOT EXISTS map_ip ( id bigint(7) NOT NULL auto_increment, ip text NOT NULL, longitude float NOT NULL default '0', latitude float NOT NULL default '0', user_agent text NOT NULL, city text NOT NULL, state text NOT NULL, country text NOT NULL, OS text NOT NULL, PRIMARY KEY (id), UNIQUE KEY id (id) ) TYPE=MyISAM;[/code] The SQL format isn't perfect, but this will create a table that can store all the information we need and a little more. Also, as a note, I found out after an hour of debugging that you cannot name a row long, as that is a keyword for a data type. Hence I used to have 'long' and 'lat' instead of 'longitude' and 'latitude'. MySQL does nothing to help you figure this out, either. Just spits back generic syntax errors. Doh! We will need to create our first PHP function here, for connecting to the MySQL database. I'm using a persistent connection so we only have to connect one time. I normally include the MySQL variables in a separate configuration file, but for this simple of a script I am including them in the connect function, as shown below. You can use the following function after you fill in your MySQL information. [code linenumbers=false]function db_connect() { // *** Create a persistant MySQL Connection for the entirety of the script *** // *** Be sure to change the variables below so you can connect! *** define ('MYSQL_SERVER', 'localhost'); define ('MYSQL_PASSWORD', 'YOUR MYSQL PASSWORD'); define ('MYSQL_USERNAME', 'YOUR MYSQL USERNAME'); define ('MYSQL_DB', 'YOUR MYSQL DATABASE'); // *** Set up the persistant link, or throw an error and quit if not successful *** if (!(@mysql_pconnect(MYSQL_SERVER, MYSQL_USERNAME, MYSQL_PASSWORD) and @mysql_select_db(MYSQL_DB))) die(sprintf("Cannot connect to database, error: %s", mysql_error())); }[/code] We will call this function at the beginning of the page. [b]Recording and Converting Visitor Info[/b] The heart of this application lies in the ability to convert the IP of every visitor into a format that we can pass to the Google Map so it can display a blip on the map. After some tedious searching, I found a PHP class that interfaces with netgeo.com's IP to GPS database. I was surprised at how hard it was to find this, but the hard part is done for you! If you're lucky enough to have a commercial package, or find an alternative free package, feel free to use these. For this example we're sticking to this one. Also, I am using another free package to determine the browser and operating system of the visitor, called Browser. Oh, the beauty of open source software! :). The function [b]add_geoip()[/b] goes through all the necessary action to ensure the Ip gets converted to a GPS coordinate, as well as retrieving the Browser and Operating system. All of this information is then added to the database, assuming this is the first hit from the visitor. We also want to record only items we will not be able to retrieve later, such as IP, Browser, Operating System. We also store the longitude and latitude, as well as city/state/country because we only want to retrieve this data one time, so we might as well do it now. This prevents page lag from hitting the GeoIP server every time we want this information. Think of it as a "cache". [code linenumbers=false]function add_geoip() { // *** add_geoip() - http://frikk.tk // *** Functions for interfacing with the GeoIP Server *** include_once "netgeo.php"; // *** Include the Browser Class, for determining OS and Browser *** include_once "browser.php"; // *** Set up the local Variables *** $info = array(); $id = ""; $query = ""; $user_agent = new Browser; $netgeo = new netgeo_class; // *** First of all, are they aready in the database? *** $query = mysql_query(sprintf("select id from map_ip where ip='%s';", $_SERVER["REMOTE_ADDR"])); list($id) = mysql_fetch_row($query); // *** If they are already in the database, exit now *** if (strlen($id)) return false; // *** If we can't get the information, theres no point in continuing *** if(!($netgeo->GetAddressLocation($_SERVER["REMOTE_ADDR"], $location))) return false; // *** Get the longitude and latitude values *** $longitude = doubleval($location["LONG"]); $latitude = doubleval($location["LAT"]); // *** Sometimes we run into problems, and longitude // and latitude both are set to 0. We will ignore these cases *** if ($longitude == 0 && latitude==0) return; /* *** Lets gather the information. We want to record things that we can't figure out later (like IP, Browser) and also things that don't require a hit (and hence page lag) to the GeoIP server later (Coords, City, State, etc). *** */ $info["IP"] = $_SERVER["REMOTE_ADDR"]; $info["User_Agent"] = $user_agent->Name; $info["OS"] = $user_agent->Platform; $info["Long"] = $longitude; $info["Lat"] = $latitude; $info["City"] = htmlentities(ucwords(strtolower($location["CITY"]))); $info["State"] = htmlentities(ucwords(strtolower($location["STATE"]))); $info["Country"] = htmlentities(ucwords(strtolower($location["COUNTRY"]))); // *** Now that we have everything we need, lets add them to the database *** if (!mysql_query(sprintf("insert into map_ip (ip, user_agent, os, longitude, latitude, city, state, country) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');", $info["IP"], $info["User_Agent"], $info["OS"], $info["Long"], $info["Lat"], $info["City"], $info["State"], $info["Country"]))) { echo "error adding your geoip entry to database!
"; echo mysql_errno().": ".mysql_error()."
"; return false; } // *** We're all done now. Return true to say that we didn't have an error *** return true; }[/code] We want to call this function one time for every page hit. Every time a visitor comes to your website for the first time, they will be added to the database and the GeoIP database will get queried to figure out their Longitude and Latitude. Easy enough? :) I'll show you how to use this a little later. [b]Creating the Google Map[/b] Before we add the user information we've collected, we want to make sure we can get a working google map. If you haven't done so already, make a basic Google Map template. Here is an example, be sure to put your API Key down on line 5! [code linenumbers=false] Google Map Test!
[/code] This page is the most basic Google Map. What we are going to do is redefine the createMarker function to handle the ability to add different information about the visitor, as well as write a PHP function to dynamically output the javascript tha creates the points (lines 44 - 46). If you do not see a Google Map with a blip somewhere in California with the above example, then you need to make sure your Google API Key is correctly set up and in the script above. [b]Writing a new createMarker function[/b] We need to rewrite the javascript function createMarker() so it can handle some more arguments and put the information we want in it (In this case: city, state, country, browser, OS). This is the function I currently use: [code linenumbers=false]function createMarker(point, city, state, country, os, browser) { // *** Updated createMarker function - http://frikk.tk *** var marker = new GMarker(point); // *** Display some html formatted text *** var html = "
" + city + ", " + state + ", " + country + "
OS: " + os + "
Browser: " + browser + "
"; GEvent.addListener(marker, 'click', function() { marker.openInfoWindowHtml(html); }); return marker; }[/code] All we've added is a formatted
element. We need to add the "style= width: 200px" because if we don't specify this value, firefox and IE display the marker differently. A well known bug that is easily fixed. Now that we have an updated createMarker function, lets add some points to utilize this. Before we can make the dynamic PHP output, we need to make sure that the function is set up correctly. Lets go back to the example Google Map, and replace lines 44-46 with this: [code linenumbers=false]var point3 = new GPoint(-117.16, 32.72); var marker3 = createMarker(point3, "San Diego", "California", "Us", "Windows", "Firefox v:1.5.0.1"); map.addOverlay(marker3);[/code] Now, when you click on the blip over california, you should see more information about the point, including "San Diego, California" and "Windows", "Firefox v:1.5.0.1", etc. [b]Tie them all together[/b] Well, at this point we have a database with all the GPS information we could want, and a working Google Map which can accept markers that display the OS, Browser, etc. Now we just have to tie these together! This function generates the javascript needed to create the markers: [code linenumbers=false]function generate_markers() { // *** Generate the Google Map Markers! *** $number_of_markers = 100; // How many markers to dispaly? $marker_html = ""; $points = array(); $query = mysql_query(sprintf("select * from map_ip order by id desc limit %s;", $number_of_markers)); while ($points = mysql_fetch_array($query)) { $point_name = sprintf("point%s", $points["id"]); $marker_name = sprintf("marker%s", $points["id"]); // *** All we're doing here is making the javascript markers *** /* They look like this: var {POINT_NAME} = new GPoint({LONG}, {LAT}); var {MARKER_NAME} = createMarker({POINT_NAME}, '{CITY}', '{STATE}', '{COUNTRY}', '{OS}', '{USER_AGENT}'); map.addOverlay({MARKER_NAME}); */ $marker_html .= sprintf("var %s = new GPoint(%s, %s);n", $point_name, $points["longitude"], $points["latitude"]); $marker_html .= sprintf("var %s = createMarker(%s, '%s', '%s', " . "'%s', '%s', '%s');n", $marker_name, $point_name, $points["city"], $points["state"], $points["country"], $points["OS"], $points["user_agent"]); $marker_html .= sprintf("map.addOverlay(%s);n", $marker_name); } return $marker_html; }[/code] Now that we have a function to output the javascript which will add the last 50 markers to the map, we need a way to output the rest of the map. [b]The Final Script[/b] Here is the final script for making the Google Map. This has all the php we've written listed first, followed by the html output. Here you go! If you copy this verbatim, you'd want to be sure to change the Google API Key, as well as name the file with a php extension. I have added, at the bottom, a function called [b]make_google_map()[/b]. All this does is output the html page to generate the map. For kicks, we're going to call this [b]gmap.php[/b]: [code linenumbers=false]GetAddressLocation($_SERVER["REMOTE_ADDR"], $location))) return false; // *** Get the longitude and latitude values *** $longitude = doubleval($location["LONG"]); $latitude = doubleval($location["LAT"]); // *** Sometimes we run into problems, and longitude // and latitude both are set to 0. We will ignore these cases *** if ($longitude == 0 && latitude==0) return; /* *** Lets gather the information. We want to record things that we can't figure out later (like IP, Browser) and also things that don't require a hit (and hence page lag) to the GeoIP server later (Coords, City, State, etc). *** */ $info["IP"] = $_SERVER["REMOTE_ADDR"]; $info["User_Agent"] = $user_agent->Name; $info["OS"] = $user_agent->Platform; $info["Long"] = $longitude; $info["Lat"] = $latitude; $info["City"] = htmlentities(ucwords(strtolower($location["CITY"]))); $info["State"] = htmlentities(ucwords(strtolower($location["STATE"]))); $info["Country"] = htmlentities(ucwords(strtolower($location["COUNTRY"]))); // *** Now that we have everything we need, lets add them to the database *** if (!mysql_query(sprintf("insert into map_ip (ip, user_agent, os, longitude, latitude, city, state, country) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');", $info["IP"], $info["User_Agent"], $info["OS"], $info["Long"], $info["Lat"], $info["City"], $info["State"], $info["Country"]))) { echo "error adding your geoip entry to database!
"; echo mysql_errno().": ".mysql_error()."
"; return false; } // *** We're all done now. Return true to say that we didn't have an error *** return true; } function generate_markers() { // *** Generate the Google Map Markers! *** $number_of_markers = 100; // How many markers to dispaly? $marker_html = ""; $points = array(); $query = mysql_query(sprintf("select * from map_ip order by id desc limit %s;", $number_of_markers)); while ($points = mysql_fetch_array($query)) { $point_name = sprintf("point%s", $points["id"]); $marker_name = sprintf("marker%s", $points["id"]); // *** All we're doing here is making the javascript markers *** /* They look like this: var {POINT_NAME} = new GPoint({LONG}, {LAT}); var {MARKER_NAME} = createMarker({POINT_NAME}, '{CITY}', '{STATE}', '{COUNTRY}', '{OS}', '{USER_AGENT}'); map.addOverlay({MARKER_NAME}); */ $marker_html .= sprintf("var %s = new GPoint(%s, %s);n", $point_name, $points["longitude"], $points["latitude"]); $marker_html .= sprintf("var %s = createMarker(%s, '%s', '%s', " . "'%s', '%s', '%s');n", $marker_name, $point_name, $points["city"], $points["state"], $points["country"], $points["OS"], $points["user_agent"]); $marker_html .= sprintf("map.addOverlay(%s);n", $marker_name); } return $marker_html; } function make_google_map() { ?> Google Map Test!
[/code] If you'll notice, I've added on line 204 the output of generate_markers. If everything is set up correctly, you should be ready to go! The only thing to remember is you have to call add_geoip() on every page you plan on recording the Ips for. It should be simple to extend this to use on any page you want. You would also want to comment out line 41 above, and call that function somewhere else. This way you're only recording information when you include the script, instead of generating the map. For example, say you have index.php that your main website is on. You could just do this: [code linenumbers=false][/code] By including the [b]gmap.php[/b], you are already running the add_geoip();. Its that simple![/quote] Well, there's "only" a problem: netgeo.com discontinued the service so I looked for a new free service and found only 3 company offering a direct embedding IP address geocoding calls: [code linenumbers=false]http://www.geoip.co.uk/ http://www.hostip.info/ (a community-based project)[/code] but I think that my choice will go to http://www.maxmind.com/app/ip-location http://www.maxmind.com/app/geolitecity there's a free monthly updated DB to download and to transfer on your server (~30mb) and then APIs for most major programming languages ([url=http://www.maxmind.com/app/installation?city=1]instructions here; [url=http://www.maxmind.com/app/php]php API here) I don't know if I have the skills to make the new integration, I think that if I'll find some free time I'll get a look :oops: regards links: http://code.google.com/apis/maps/documentation/ http://code.google.com/apis/ajax/documentation/ http://code.google.com/support/bin/answer.py?answer=80200&topic=11364 http://code.google.com/support/bin/answer.py?answer=87134&topic=11364 http://groups.google.com/group/Google-Maps-API/web/resources-non-google-geocoders ----------------------------------- Mighty Gorgon Sun 02 Mar, 2008 12:43 Re: Track Visitors To Your Website Using Google Maps ----------------------------------- Thank you very much! This is a really cool integration. :wink: When IP 1.2 is out, please update instructions for that release and post it in customizations forum. :wink: ----------------------------------- KugeLSichA Sun 02 Mar, 2008 20:03 Re: Track Visitors To Your Website Using Google Maps ----------------------------------- sounds cool and very interesting... i bookmarked this topic and if i have some time, i´ll check this... thanks ----------------------------------- ieio Mon 03 Mar, 2008 08:48 Re: Track Visitors To Your Website Using Google Maps ----------------------------------- sorry MG but I'm not allowed to post in http://www.icyphoenix.com/viewforum.php?f=21 maybe someone from the staff can move this topic to the right section? I need some help for the last integration, maybe the istructions will remain the same since in the end I only added a block via cms... :oops: ----------------------------------- Mighty Gorgon Mon 03 Mar, 2008 22:03 Re: Track Visitors To Your Website Using Google Maps ----------------------------------- If it is working in latest release, we will move it. Can you confirm this working in IP 1.2? ----------------------------------- ieio Thu 06 Mar, 2008 22:58 Re: Track Visitors To Your Website Using Google Maps ----------------------------------- icy updated to 1.2 on march 4th and still working [img]http://www.icyphoenix.com/images/smiles/0014.gif[/img] ----------------------------------- Zuker Fri 07 Mar, 2008 13:30 Re: Track Visitors To Your Website Using Google Maps ----------------------------------- So moving ;) ----------------------------------- Chaotic Fri 07 Mar, 2008 13:53 Re: Track Visitors To Your Website Using Google Maps ----------------------------------- I like the idea of seeing your visitors but I'd also like to see the Phoogle (Google) Map working in IP. I used this mod on my forum prior to using IP and it worked great! http://www.phpbb.com/community/viewtopic.php?f=16&t=496246 Sample Site 2: Sample Site running v1.0.3 http://bassface3d.com/v103/ Admin Username: testadmin Admin Password: testadmin ----------------------------------- novice programmer Fri 07 Mar, 2008 15:37 Re: Track Visitors To Your Website Using Google Maps ----------------------------------- See this: http://www.icyphoenix.com/viewtopic.php?t=3165 It is for Icy Phoenix. ----------------------------------- Chaotic Fri 07 Mar, 2008 16:56 Re: Track Visitors To Your Website Using Google Maps ----------------------------------- [quote user="novice programmer" post="25520"]See this: http://www.icyphoenix.com/viewtopic.php?t=3165 It is for Icy Phoenix.[/quote] The website requires you login to download that mod. I registered but still haven't received an account activation e-mail. Oh well. ----------------------------------- ThE KuKa Fri 07 Mar, 2008 18:50 Re: Track Visitors To Your Website Using Google Maps ----------------------------------- Thanks again [b]ieio[/b] for update this featore for IP 1.2 :wink: Nice work :D ----------------------------------- ieio Fri 07 Mar, 2008 22:35 Re: Track Visitors To Your Website Using Google Maps ----------------------------------- [b]ThE KuKa[/b] thank you but really not a big work :oops: if i'll get a local geocoding service and all users recorded I think it will be a greater goal [b]Chaotic[/b], sorry but I wanted something different from Phoogle: as I read, it "shows a fully interactive Google Map where your Users can input their location" but I wanted to record users via ip addresses and get an automatic reverse coding in latitude&longitude and then show the location in google map :oops: ----------------------------------- moreteavicar Fri 07 Mar, 2008 23:56 Re: Track Visitors To Your Website Using Google Maps ----------------------------------- Good work [b]ieio[/b]... One of those things that one doesn't automatically think of having on a site, but once you see it, you want it! ;) ----------------------------------- moreteavicar Sat 08 Mar, 2008 00:11 Re: Track Visitors To Your Website Using Google Maps ----------------------------------- [quote user="ieio" post="25029"]The only thing to remember is you have to call add_geoip() on every page you plan on recording the Ips for. It should be simple to extend this to use on any page you want. You would also want to comment out line 41 above, and call that function somewhere else. This way you're only recording information when you include the script, instead of generating the map. For example, say you have index.php that your main website is on.[/quote] I think you'll be better off adding it to page_header.php, then it will be called whatever page is viewed. ----------------------------------- moreteavicar Sat 08 Mar, 2008 00:50 Re: Track Visitors To Your Website Using Google Maps ----------------------------------- Ah... I see the main source of the info... http://frikk.tk/comments-274-03.18.06.htm maxmind integration shouldn't be too difficult, there are some sample code - you just upload and include their php code files, and call the functions and retrieve the country / region variable where needed. E.g. instead of calling (including) netgeo.php in add_geoip(), you'd use: [code linenumbers=false] include("geoip.inc"); include("geoipregionvars.php");[/code] then replace [code linenumbers=false] $info["City"] = htmlentities(ucwords(strtolower($location["CITY"]))); $info["State"] = htmlentities(ucwords(strtolower($location["STATE"]))); $info["Country"] = htmlentities(ucwords(strtolower($location["COUNTRY"]))); [/code] with something like [code linenumbers=false] $gi = geoip_open("/usr/local/share/GeoIP/GeoIPRegion.dat",GEOIP_STANDARD); list ($countrycode,$region) = geoip_region_by_addr($gi, $info["IP"]); $info["City"] = htmlentities(ucwords(strtolower($region))); $info["Country"] = htmlentities(ucwords(strtolower($countrycode))); geoip_close($gi);[/code] You should also remove the longitude and latitude lines from there... Can't check all this yet to see if works... if list ($countrycode,$region) = geoip_region_by_addr($gi, $info["IP"]); isn't working, try replacing with: [code linenumbers=false] $user_ip = $_SERVER["REMOTE_ADDR"]; list ($countrycode,$region) = geoip_region_by_addr($gi, $user_ip ); [/code] ----------------------------------- moreteavicar Sat 08 Mar, 2008 00:53 Re: Track Visitors To Your Website Using Google Maps ----------------------------------- Oh yes, of course, this line: $gi = geoip_open("/usr/local/share/GeoIP/GeoIPRegion.dat",GEOIP_STANDARD); Depends on where you upload the region data file, so needs changing to suit... ----------------------------------- babbman Sat 08 Mar, 2008 03:33 Re: Track Visitors To Your Website Using Google Maps ----------------------------------- [quote user="moreteavicar" post="25563"] I think you'll be better off adding it to page_header.php, then it will be called whatever page is viewed.[/quote] I almost hate asking this question... but I'm not a php programmer at all... I have the gmap and other associated php files in the root. If I wanted to put the add_geoip() function call in page_header.php, what's the proper syntax? Thanks! ----------------------------------- moreteavicar Sat 08 Mar, 2008 19:58 Re: Track Visitors To Your Website Using Google Maps ----------------------------------- [quote user="babbman" post="25568"][quote user="moreteavicar" post="25563"] I think you'll be better off adding it to page_header.php, then it will be called whatever page is viewed.[/quote] I almost hate asking this question... but I'm not a php programmer at all... I have the gmap and other associated php files in the root. If I wanted to put the add_geoip() function call in page_header.php, what's the proper syntax? Thanks![/quote] Actually I was jumping the gun a bit when I said that - I had in mind the idea of putting the function inside page_header.php and calling it from there. If you were going to use the original files, then use: [code linenumbers=false] include_once($phpbb_root_path . 'gmap.' . $phpEx); [/code] Put it somewhere near the top of includes/page_header.php, e.g. after the line [code linenumbers=false]define('HEADER_INC', true);[/code] let me know if that works ;) ----------------------------------- ieio Sat 08 Mar, 2008 23:25 Re: Track Visitors To Your Website Using Google Maps ----------------------------------- [b]moreteavicar[/b], really thank you for the advices! I think I will bother you with some other questions as soon as I'll try the final integration :oops: best regards ----------------------------------- moreteavicar Mon 10 Mar, 2008 17:47 Re: Track Visitors To Your Website Using Google Maps ----------------------------------- Hi, I thought I'd have a play with this, as I'm thinking of using it on my site. I've got it working nicely with the MaxMind dat file - just install these in the same location as gmap.php (as per instructions below). Here is my version of gmap.php (note I've added some lines to exclude bots): [code linenumbers=false] longitude; $location["LAT"] = $record->latitude; // *** Get the longitude and latitude values *** $longitude = doubleval($location["LONG"]); $latitude = doubleval($location["LAT"]); // *** Sometimes we run into problems, and longitude // and latitude both are set to 0. We will ignore these cases *** if ($longitude == 0 && latitude==0) return; /* *** Lets gather the information. We want to record things that we can't figure out later (like IP, Browser) and also things that don't require a hit (and hence page lag) to the GeoIP server later (Coords, City, State, etc). *** */ $info["User_Agent"] = $user_agent->Name; $info["OS"] = $user_agent->Platform; $info["Long"] = $longitude; $info["Lat"] = $latitude; $info["City"] = htmlentities(ucwords(strtolower($record->city))); $info["State"] = htmlentities(ucwords(strtolower($GEOIP_REGION_NAME[$record->country_code][$record->region]))); $info["Country"] = $record->country_code; // *** Now that we have everything we need, lets add them to the database *** if (!mysql_query(sprintf("insert into map_ip (ip, user_agent, os, longitude, latitude, city, state, country) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');", $info["IP"], $info["User_Agent"], $info["OS"], $info["Long"], $info["Lat"], $info["City"], $info["State"], $info["Country"]))) { echo "error adding your geoip entry to database!
"; echo mysql_errno().": ".mysql_error()."
"; return false; } // *** We're all done now. Return true to say that we didn't have an error *** return true; } function generate_markers() { // *** Generate the Google Map Markers! *** $number_of_markers = 100; // How many markers to dispaly? $marker_html = ""; $points = array(); $query = mysql_query(sprintf("select * from map_ip limit %s;", $number_of_markers)); while ($points = mysql_fetch_array($query)) { $point_name = sprintf("point%s", $points["id"]); $marker_name = sprintf("marker%s", $points["id"]); // *** All we're doing here is making the javascript markers *** /* They look like this: var {POINT_NAME} = new GPoint({LONG}, {LAT}); var {MARKER_NAME} = createMarker({POINT_NAME}, '{CITY}', '{STATE}', '{COUNTRY}', '{OS}', '{USER_AGENT}'); map.addOverlay({MARKER_NAME}); */ $marker_html .= sprintf("var %s = new GPoint(%s, %s);n", $point_name, $points["longitude"], $points["latitude"]); $marker_html .= sprintf("var %s = createMarker(%s, '%s', '%s', " . "'%s', '%s', '%s');n", $marker_name, $point_name, $points["city"], $points["state"], $points["country"], $points["OS"], $points["user_agent"]); $marker_html .= sprintf("map.addOverlay(%s);n", $marker_name); } return $marker_html; } function make_google_map() { ?> Google Map Test!
[/code] You could use this as a stand-alone page, and then view it within another page by using