0

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.

YodaCode
  • 21
  • 6
  • 1
    I’m voting to close this question because it isn't about a programming problem. For help finding your log files, you might be better off with https://webmasters.stackexchange.com/ – Quentin Jun 29 '22 at 15:00
  • This may involve making configurations in Apache – YodaCode Jun 29 '22 at 15:12
  • Still not a programming problem. – Quentin Jun 29 '22 at 15:13
  • in case you have cpanel / vhm you can see the visitor sections if you can access logs by limitations . some had filters and you can put the name of pdf of partial ..i would try ".pdf" so to see all pdf accessed ,in case are many –  Jun 29 '22 at 16:43
  • Please provide enough code so others can better understand or reproduce the problem. – zidniryi Jun 30 '22 at 07:46
  • @Constantin I need to create a system to analyze which pages are being visited, I don't use Cpanel, anyway the system will have to record the visits in a database and then display it to the site administrators. I just don't know how to capture hits in PDF files, I think there may be a solution using apache/htaccess and PHP, but I'm not sure how to do that. I just need some direction on how this can be done. I'm thinking of doing as a friend suggested, which is to get apache acesslog access, but i am not sure if it is the best approach – YodaCode Jun 30 '22 at 17:27
  • Hi @zidniryi I have no code yet. I just need some guidance on how that can be done – YodaCode Jun 30 '22 at 17:30

2 Answers2

0

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.

DigitalDesignDj
  • 1,725
  • 15
  • 16
  • That will help. Thanks. What happens when access.log gets too big? they are excluded? – YodaCode Jun 29 '22 at 15:24
  • I use nginx so I am not sure, but look in that folder and there should be some kind of log rotation happening automagically. Check the manual! https://httpd.apache.org/docs/2.4/logs.html – DigitalDesignDj Jun 29 '22 at 15:49
0

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)

4b0
  • 21,981
  • 30
  • 95
  • 142