View how many people have accessed pdf

2

I have a pdf on my server and I put it available through a link, is there a way to control how many people access the pdf?

    
asked by anonymous 11.03.2015 / 17:55

2 answers

1

1 phase - collecting accesses and viewing the file

// abrir o arquivo através do link do seu servidor
$file = 'file.pdf';
// nome do arquivo
$filename = 'file.pdf'; /* Nota: sempre use .pdf no final. */

// Conectando ao banco
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
// Realizando a query
mysqli_query($link, "UPDATE acessos SET contador = contador+1 WHERE 'nomearquivo' = $filename);

// exibindo o arquivo
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
header('Accept-Ranges: bytes');

@readfile($file);

2 phase - see total hits

   // essa parte vc pode coloca no local que vai aparecer o total
   $link = mysqli_connect("localhost", "my_user", "my_password", "world");
   $result = mysqli_query($link, "select contador from acessos where 'file' =  $filename);
   if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        echo "$row["contador"]";
    }
    
11.05.2015 / 02:01
-2

Now if you want a fast method

1st choose your code in one of those that generates online

ex: link

2nd create a file ex: contacliques.html

and put in it

<meta http-equiv="Refresh" content="0; url=http://linkdopdf>

codigo do contador que pegou no site

Just remember that this is not accurate and only serves to have control of the file.

    
11.03.2015 / 18:05