Home > front end >  How can I know which static pages on my site are being visited?
How can I know which static pages on my site are being visited?

Time:07-01

How can I know which static pages on my site are being visited? By static pages I mean PDF for the most part.

I use Apache and PHP.

CodePudding user response:

You need to look at your apache config. It will specify the location of logfiles that you want to look at.

I believe the default location is /var/log/apache2 once there you can monitor traffic in real time with something like tail -f access.log or you can process the logfiles to get an idea of how many hits the resources are getting.

CodePudding user response:

assuming you had in xampp (preferable windows cause for sure cmod write right are on) the folder 0 and you can access http://localhost/0/ cause the server is on ,

assuming you use links like this to acces each pdf file:

http://localhost/0/file1.pdf

http://localhost/0/file2.pdf

assuming your php.ini settings does allow to run error_log function

you have these files .htaccess

RewriteEngine On
RewriteBase /0/
RewriteRule ^.*\.pdf$ ?countfile=$0 [R=301,L,QSA]

# i'm not so pro with .htaccess so i used work based on
#https://stackoverflow.com/questions/10949685/htaccess-redirect-file-type
#https://stackoverflow.com/questions/1231067/htaccess-rewrite-for-query-string
#https://stackoverflow.com/questions/20439192/rewrite-url-relative-to-current-directory

index.php

<?php
    isset($_REQUEST['countfile'])and error_log($_REQUEST['countfile']."\r\n",3,'logpdf.txt');
    header('');
    //include($_REQUEST['countfile']);
    header("Content-type:application/pdf");
    header("Content-Disposition:inline;filename='".$_REQUEST['countfile']);
    readfile($_REQUEST['countfile']);
?>

results.php

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="CustaRoolez">
<title>just for fun</title>
</head>
<body>
<?php
if(file_exists('logpdf.txt')){
    $files=file('logpdf.txt');
    $statistics=array_count_values($files);
    foreach($statistics as $file => $cnt){
        echo 'the file: '.$file.' was accesed by'.$cnt.' times<br>';
    }
}
?>
</body>
</html>

then should be the fastest custom method to logs visits statistics to count pdf access files

on https://www.real-domain-whaterver.extension .htaccess may be like this (you should set the route ,isn't automaticly) so for https://www.real-domain-whaterver.extension/ <---- '/' :

RewriteEngine On
RewriteBase /
RewriteRule ^.*\.pdf$ ?countfile=$0 [R=301,L,QSA]

remember you should have right to write so on real public domain you could modify in index.php

error_log($_REQUEST['countfile']."\r\n",3,'logpdf.txt'); 

to

error_log($_REQUEST['countfile']."\r\n",3,'/someFOLDERtoLOG/logpdf.txt');

and results.php

if(file_exists('logpdf.txt')){
    $files=file('logpdf.txt');

to

if(file_exists('/someFOLDERtoLOG/logpdf.txt')){
    $files=file('/someFOLDERtoLOG/logpdf.txt');

and sure create someFOLDERtoLOG and setting cmod 775 or verify if is already(depend by administrator settings)

  • Related