【问题标题】:How can I know which static pages on my site are being visited?我如何知道正在访问我网站上的哪些静态页面?
【发布时间】:2022-07-01 15:10:08
【问题描述】:

我如何知道正在访问我网站上的哪些静态页面? 我所说的静态页面主要是指 PDF。

我使用 Apache 和 PHP。

【问题讨论】:

  • 我投票结束这个问题,因为它与编程问题无关。如需帮助查找日志文件,您最好使用webmasters.stackexchange.com
  • 这可能涉及在 Apache 中进行配置
  • 仍然不是编程问题。
  • 如果您有 cpanel/vhm,如果您可以通过限制访问日志,则可以看到访问者部分。有些有过滤器,你可以把部分pdf的名称..我会尝试“.pdf”以便查看所有访问的pdf,以防很多
  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: php apache analytics


【解决方案1】:

您需要查看您的 apache 配置。它将指定您要查看的日志文件的位置。

我相信默认位置是/var/log/apache2,您可以使用tail -f access.log 之类的方式实时监控流量,或者您可以处理日志文件以了解资源获得了多少点击。

【讨论】:

  • 这会有所帮助。谢谢。当 access.log 变得太大时会发生什么?他们被排除在外了吗?
  • 我使用 nginx,所以我不确定,但是查看那个文件夹,应该会自动发生某种日志轮换。检查手册! httpd.apache.org/docs/2.4/logs.html
【解决方案2】:

假设您在 xampp 中(最好的 windows 原因确保 cmod 写入权限已打开)文件夹 0 并且您可以访问 http://localhost/0/ 因为服务器已打开,

假设您使用这样的链接来访问每个 pdf 文件:

http://localhost/0/file1.pdf

http://localhost/0/file2.pdf

假设您的 php.ini 设置允许运行 error_log 函数

你有这些文件 .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>

那么应该是记录访问统计以计算 pdf 访问文件的最快的自定义方法

https://www.real-domain-whaterver.extension .htaccess 可能是这样的(你应该设置路由,不是自动的) 所以https://www.real-domain-whaterver.extension/ &lt;---- '/'

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

请记住,您应该有权在您可以修改的真实公共领域上进行写作 在 index.php

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

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

results.php

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

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

并确保创建 someFOLDERtoLOG 并设置 cmod 775 或验证是否已经(取决于管理员设置)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-23
    • 2017-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-29
    相关资源
    最近更新 更多