a little help for a little counter

a little help for a little counter

am 13.04.2008 00:36:19 von nintesa

Hello from Italy!

I'm trying to create a little script (php/mysql/javascript) to record
visits of some of my sites. I have sites www.a.com, www.b.com ecc... and
I have my counter script on www.phptrack.net.

I compare the results of my counter with shinystat: visits (I would
better call it "pages viewed") is perfectly ok!! but I have a too big
number of visitors. I think there shoul be a problem with sessions...
could someone help me?

The js file is:

var screen_x=window.screen.width;
var screen_y=window.screen.height;
var cur_location = escape(window.location.toString());
var referer = escape(document.referrer);
document.write(' src="http://phptrack.net/phptrack.php?site_id='+phptrack_sit e_id+'&s_x='+screen_x+'&s_y='+screen_y+'&cur_loc='+cur_locat ion+'&referer='+referer+'"
width="0" height="0" border="0"/>');

and the php script is:


session_start();

require('components/phptrack/configure.php');
require('includes/classes/db.php');
$db = new db(DB_HOST,DB_NAME,DB_USER,DB_PASSWORD);


$site_id=(int)$_GET['site_id'];

//$_SESSION[$site_id.'_visitor_id']
//This because a visitor can visit both www.a.com and www.b.com in the
//same session!!


if (!($_SESSION[$site_id.'_visitor_id']>0)) {
$sql_data = new sql_data;
$sql_data->add('previous_visitor_id',0);
$sql_data->add('site_id',$site_id);
$sql_data->add('ip',$_SERVER['REMOTE_ADDR']);
$sql_data->add('language',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
$sql_data->add('browser',$_SERVER['HTTP_USER_AGENT']);
$sql_data->add('screen_x',(int)$_GET['s_x']);
$sql_data->add('screen_y',(int)$_GET['s_y']);
$sql_data->perform('raw_visitors');
$_SESSION[$site_id.'_visitor_id']=$db->insert_id();
}


$sql_data = new sql_data;
$sql_data->add('site_id',$site_id);
$sql_data->add('visitor_id',$_SESSION[$site_id.'_visitor_id' ]);
$sql_data->add('time','now()');
$sql_data->add('location',$_GET['cur_loc']);
$sql_data->add('referer',$_GET['referer']);
$sql_data->perform('raw_visits');
?>

Thanks...