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?
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?
// 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);
// 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"]";
}
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.