不匹配的计数器值,Google 缩短器与 php 访客计数器

mismatched counter value, Google shortener vs php visitor counter

这是我想要实现的流程:

用户

  1. 点击共享 link(点击 Google 缩短 link)
  2. 重定向到计数器 (counter.php)
  3. 重定向到网页(网站页面)

我对 Google 缩短器和我自己的计数器的计数器值有疑问 - 值总是不同。我的计数器值总是比Google短的值大,我自己的代码计数器有什么问题吗?

counter.php :

//redirect to ?
$destination = "page1";
$destination_mobile = "page2";
$destination_article = "page3";

//connection
$con = mysqli_connect('localhost','root','','db_omron');
if (!$con) {    
    die('Could not connect: ' . mysqli_error($con));
}

//source contents
$id = mysqli_real_escape_string($con, $_GET['id']);
//internal
if($id=='101010'){$source='Quiz';}
else if($id=='101011'){$source='Quiz mobile';}
else if($id=='101020'){$source='Event';}
else if($id=='101021'){$source='Event mobile';}
else if($id=='101031'){$source='SMS';}
else if($id=='101040'){$source='News';}
else if($id=='101041'){$source='News mobile';}
else if($id=='101050'){$source='Banner';}
else if($id=='999990'){$source='tester';}
else{$source='n/a';}

date_default_timezone_set('Asia/Jakarta');
$today = date("Y-m-d");

//1.get old data
$sql="SELECT * FROM `click_counter` WHERE `id_source` = $id ORDER BY `date` DESC";
$result = mysqli_query($con,$sql);

$row = mysqli_fetch_array($result);
$oldTotal=$row['total'];
$oldDate=$row['date'];

//2.check if today is in database
if($today==$oldDate){
    //update
        $newTotal = $oldTotal+1;
        $newSqlUpdate="UPDATE `click_counter` SET `total` = '$newTotal' WHERE `id_source` = $id AND `click_counter`.`date` = '$today'";
        $newResult = mysqli_query($con,$newSqlUpdate);
    }else{
    //insert
        $newSqlInsert="INSERT INTO `click_counter` (`date`, `id_source`, `source`, `total`) VALUES ('$today', '$id', '$source', '1')";  
        $newEntry = mysqli_query($con,$newSqlInsert);
    }

//close connection
mysqli_close($con);

//redirecting page 

$a = substr("$id" , -1);
if ( $a == "1" ){
    header("Location:".$destination_mobile); 
}else if(($id=='102120') || ($id=='102130')){
    header("Location:".$destination_article); 
}else{
    header("Location:".$destination);
}

exit();

I have a problem with the counter value from the Google shortener and my own counter - the value always different. My counter value is always bigger than Google shorter value, is there anything wrong with my own code counter?

Google Analytics 通过 JavaScript 进行跟踪,因此,大多数机器人和任何未启用 JS 的用户都不会在其数量中进行跟踪。这几乎可以肯定是造成您的差异的原因。