|
Page 2 of 2
|
moreteavicar
Joined: August 2006
Posts: 608
Location:  Classified
|
 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...
|
#16 Sat 08 Mar, 2008 00:53 |
|
Sponsors

|
Icy Phoenix is an open source project, you can show your appreciation and support future development by donating to the project.
|
| |
babbman 
Joined: October 2006
Posts: 31
|
 Re: Track Visitors To Your Website Using Google Maps
I think you'll be better off adding it to page_header.php, then it will be called whatever page is viewed.
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!
|
#17 Sat 08 Mar, 2008 03:33 |
|
moreteavicar
Joined: August 2006
Posts: 608
Location:  Classified
|
 Re: Track Visitors To Your Website Using Google Maps
I think you'll be better off adding it to page_header.php, then it will be called whatever page is viewed.
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!
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:
include_once($phpbb_root_path . 'gmap.' . $phpEx); Put it somewhere near the top of includes/page_header.php, e.g. after the line define('HEADER_INC', true); let me know if that works
|
#18 Sat 08 Mar, 2008 19:58 |
|
ieio 
Joined: April 2007
Posts: 55
Location:
|
 Re: Track Visitors To Your Website Using Google Maps
moreteavicar, 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  best regards
____________ rescued by MG :10k_0025:
|
#19 Sat 08 Mar, 2008 23:25 |
|
moreteavicar
Joined: August 2006
Posts: 608
Location:  Classified
|
 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):
<?php
/*
// ############################################################################
Google Maps! - http://frikk.tk - modded by MoreTeaVicar to use MaxMind geo
Data. Also excludes bots from the map.
Installation:
Obtain MaxMind files from http://www.maxmind.com/download/geoip/api/php/
and dat file from http://www.maxmind.com/app/geolitecity
Upload the MaxMind files: geoip.inc, geoipcity.inc, geoipregionvars.php
and GeoLiteCity.dat to the same directory as this program (or else change the
include lines for a different directory).
Still requires original browser.php file from frikk's pack, but NOT netgeo.php.
// ############################################################################
*/
db_connect();
add_geoip();
// *** Comment this line out if you are including this file from another script ***
make_google_map();
// ######## Function Listings that we wrote earlier in the tutorial! ###########
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()));
}
function add_geoip()
{
// *** add_geoip() - http://frikk.tk
// Modded by MoreTeVicar
// Speed improvement: Perform all checks before including any files!
// Exclude popular search bots / spiders from IP records
// Performs crude check for bots via browser agent. Disadvantage - spam bots use spoof user agents
// to pretend to be good bots - a better method would be to use php ip hostname function, but not all
// good search bots have a defined username under php function.
// $hostname = gethostbyaddr($info["IP"]);
$ua = $_SERVER['HTTP_USER_AGENT'];
if(stristr($ua, 'msnbot') || stristr($ua, 'googlebot') || stristr($ua, 'lycos') || stristr($ua, 'Scooter') ||
stristr($ua, 'Mercator') || stristr($ua, 'Slurp') || stristr($ua, 'YahooSeeker') )
{
return false;
}
// If not a bot, then do the rest of the job
$id = ""; $query = "";
$info = array();
$info["IP"] = $_SERVER["REMOTE_ADDR"];
// *** First of all, are they aready in the database? ***
$query = mysql_query(sprintf("select id from map_ip where ip='%s';", $info["IP"]));
list($id) = mysql_fetch_row($query);
// *** If they are already in the database, exit now ***
if (strlen($id))
return false;
// We have a new visitor, so only now do we include our files to generate geographical data
include("./geoipcity.inc");
include("./geoipregionvars.php");
// *** Include the Browser Class, for determining OS and Browser ***
include("browser.php");
$gi = geoip_open("GeoLiteCity.dat",GEOIP_STANDARD);
$user_agent = new Browser;
// Get geographical data
// If we don't have any data, abort
if (!$record = geoip_record_by_addr($gi,$info["IP"]))
{ return false;
}
$location["LONG"] = $record->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!<br>";
echo mysql_errno().": ".mysql_error()."<BR>";
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()
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Google Map Test!</title>
<script src="http://maps.google.com/maps?file=api&v=1&key=INSERT API KEY HERE" type="text/javascript"></script>
</head>
<body>
<div id="map" style="width: 750px; height: 450px"></div>
<script type="text/javascript">
//<![CDATA[
// *** Create a marker with simple text in it ***
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 = "<div style="width: 200px">" + city +
", " + state + ", " + country + "<br><u>OS</u>: " + os +
"<br><u>Browser</u>: " + browser + "</div>";
GEvent.addListener(marker, 'click', function() {
marker.openInfoWindowHtml(html);
});
return marker;
}
// *** Create the map instance ***
var map = new GMap(document.getElementById("map"));
// *** Add some controls to it ***
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
// *** Center / Zoom it where? ***
map.centerAndZoom(new GPoint(0, 0),16); // 16 = Zoom Out All the Way
// *** Add a point. First we define the coordinates, then we
// make the marker, or blip, for it. Finally we add it
// to the map "overlay". We need to do this for every
// point we will be displaying for each visitor. If you
// haven't figured out, this is the part that will be
// dynamically output by a PHP we will write ***
<? echo generate_markers(); ?>
//]]>
</script>
</body>
</html>
<?
}
?>
You could use this as a stand-alone page, and then view it within another page by using <iframe> method.
I'm thinking of modifying it so that it works more within IP, for instance the function add_geoip() would be defined and called in page_header.php - this then means you can avoid using the SQL connect function and use the standard phpbb SQL connect queries - it also means add_geoip() will be called whatever page is being visited, so that a new visitor's IP will always be logged. The rest of the functions - e.g. generate_markers() and make_google_map() could then go in a block file.
|
#20 Mon 10 Mar, 2008 17:47 |
|
moreteavicar
Joined: August 2006
Posts: 608
Location:  Classified
|
 Re: Track Visitors To Your Website Using Google Maps
Something else that might interest you. Heres some javascript to modify the google map to suit the browser window size.
Look for:
// *** Create the map instance ***
var map = new GMap(document.getElementById("map"));
Replace with:
var winW = 460, winH = 320;
if( typeof( window.innerWidth ) == 'number' ) {
//Netscape or Non-IE
winW = window.innerWidth-16;
winH = window.innerHeight-16;
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
//IE 6+ in 'standards compliant mode'
winW = document.documentElement.clientWidth-20;
winH = document.documentElement.clientHeight-20;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
//IE 4 compatible
winW = document.body.clientWidth-20;
winH = document.body.clientHeight-20;
}
// *** Create the map instance ***
var map = new GMap(document.getElementById("map"),
{ size: new GSize(winW, winH) } );
*Edit* And if you display it in an IP page, with left sidebar / menubar, also subtract the left sidebar width.
E.g. If sidebar width =180, then in the above javascript lines, replace -16 with -196 and -20 with -200. If you want fixed width, just remove the if else lines and keep: var winW = 460, winH = 320; (change values to suit).
|
#21 Mon 10 Mar, 2008 21:28 |
|
babbman 
Joined: October 2006
Posts: 31
|
 Re: Track Visitors To Your Website Using Google Maps
REALLY excellent mod. Thank you moreteavicar for all of your work....
Now for a question... is there an easy way to change the marker used on the map to something custom?
|
#22 Tue 11 Mar, 2008 03:42 |
|
moreteavicar
Joined: August 2006
Posts: 608
Location:  Classified
|
 Re: Track Visitors To Your Website Using Google Maps
For those interested in this thread, I have now created a standalone mod to display phoogle (php+google) maps of site visitors, in portal blocks, and can be found here:
http://www.icyphoenix.com/viewtopic.php?f=21&t=3822
This requires the bare minimum of code tweaking. After uploading the files you should be running in less than 3 minutes!
*EDIT* Could not upload full installation with GeoLiteCity.dat (even though compressed) - seems to be a problem uploading 15MB files on this board (Error no mode specified on posting.php - although mode was new at start of upload).
Last edited by moreteavicar on Tue 11 Mar, 2008 17:00; edited 1 time in total |
#23 Tue 11 Mar, 2008 16:26 |
|
moreteavicar
Joined: August 2006
Posts: 608
Location:  Classified
|
 Re: Track Visitors To Your Website Using Google Maps
REALLY excellent mod. Thank you moreteavicar for all of your work....
Now for a question... is there an easy way to change the marker used on the map to something custom?
Good question... yes you can...
|
#24 Tue 11 Mar, 2008 16:46 |
|
tibi2007 
Joined: January 2008
Posts: 14
|
 Re: Track Visitors To Your Website Using Google Maps
nice mod
|
#25 Fri 14 Mar, 2008 10:00 |
|
|
Page 2 of 2
|
Was this topic useful?
Was this topic useful?
| Link this topic |
| URL |
|
| BBCode |
|
| HTML |
|
You cannot post new topics You cannot reply to topics You cannot edit your posts You cannot delete your posts You cannot vote in polls You cannot attach files You can download files You cannot post calendar events
|
|
|
|