1

I have made a tracking website in php which tracks number of clicks on a specific link - for affiliate links tracking. what I am doing is:

When a user clicks a link provided by my website, he goes to my website which after recording its ip address redirects the user to another address mapped to the link user clicked. A counter increments the number of click after validating ip.

The problem I am facing is that when i compare the number of clicks in my website and that of facebook results, my result is many times more. I don't know what is the cause of that.

My results:

enter image description here

Facebook results:

enter image description here

enter image description here

My question is that why is there a difference? if facebook has some additional checks does someone know what they are? or are they private? or facebook just reduces the number of clicks?

Help would be really appreciated. I am stuck here.

Here is my code to check the visitors ip and increment the click counter:

<?php 
require_once "dbdata.php";  

if(isset($_GET['linkid']) && !empty($_GET['linkid'])){


$id =  $_GET['linkid'];          //getting link id to fetch data from database
$ip = $_SERVER['REMOTE_ADDR'];   // getting visitors ip address

//database connection
@$db = new mysqli(hostname,username,password,dbname) or die(json_encode(array("status"=>"Can not connect  (Database Connection Error)")));


  //getting data from table
  $query = "select * from links_shared where id = $id ;";
  $result_link = $db -> query($query) or die(json_encode(array("status"=>"Error Fetching previous income data")));
  $row_link = $result_link-> fetch_assoc();

  $link = $row_link['orignal']; //the link to be redirect the user to

  header("Location:".$link); //redirected

  if($row_link['status'] == "live"){   //status of link should be live


    $array_ip = explode(",", $row_link['ip']); //comma sepearted string of ips to array

    if(!in_array($ip, $array_ip)){   //check if ip is not already present

        $query = "select * from links_deleted where url = '$link' ;";   //getting block list
        $result_del = $db -> query($query) or die(json_encode(array("status"=>"Can not select deleted")));

        if($result_del -> num_rows <1){  //check if link  not in block list

            $concat = ",".$ip; 
            echo $query = "update links_shared set clicks = (clicks + 1), ip = concat(ip,'$concat') where id= $id; ";
            $result_update = $db -> query($query) or die(json_encode(array("status"=>"can not update clicks")));
        }   

    }

  }

}
?>
Hamza Tasneem
  • 74
  • 3
  • 12

1 Answers1

2

Either facebook is invalidating clicks that your script accepts (eg: untrusted IPs, repeated IPs, automatic bot detection...) or more simply facebook only sees clicks from its platform but your script receives all clicks from everywhere.

Of course there could also be a problem with your script itself, but since you don't show it, I can't address that.

BeetleJuice
  • 39,516
  • 19
  • 105
  • 165