跟踪文件完整下载

发布于 2024-08-23 01:07:38 字数 93 浏览 8 评论 0原文

我有一个文件托管网站,用户可以通过下载获得奖励。所以我想知道是否有一种方法可以跟踪访问者是否下载了整个文件,这样就不会为了奖励而进行虚假的部分下载。

谢谢。

I have a file hosting site and users earn a reward for downloads. So I wanted to know is there a way I can track whether the visitor downloaded whole file so that there are no fake partial downloads just for rewards.

Thank You.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凌乱心跳 2024-08-30 01:07:38

如果您可以监视 Web 服务器返回的 HTTP 响应代码并将它们与生成它们的会话联系起来,那么您就可以开展业务了。

响应代码 206 表明系统已传送部分信息,但不是全部。当文件的最后一块发出时,它不应该有响应代码 206。

如果您可以通过将会话代码放入 URL 中来将其与用户会话联系起来,那么您可以根据简单的日志聚合来给出分数。

If you could monitor the HTTP response codes returned by your web server and tie them back to the sessions that generated them, you would be in business.

A response code of 206 shows that the system has delivered some of the information but not all of it. When the final chunk of the file goes out, it should not have a response code of 206.

If you can tie this to user sessions by putting the session code inside the URL, then you could give points based on a simple log aggregation.

最后的乘客 2024-08-30 01:07:38

我在文件托管网站上实现了类似的解决方案。

您想要做的是使用 register_shutdown_function 回调,它允许您检测 php 脚本执行的结束,无论结果如何。

然后,您希望将文件放在服务器上的非网络可访问位置,并通过 php: 进行下载:想法是您希望能够跟踪已传递给客户端的字节数。

这是实现的基本方法(例如:)

<?php
register_shutdown_function('shutdown', $args);

$file_name = 'file.ext';
$path_to_file = '/path/to/file';
$stat = @stat($path_to_file);

//Set headers
header('Content-Type: application/octet-stream');
header('Content-Length: '.$stat['size']);
header('Connection: close');
header('Content-disposition: attachment; filename='.$file_name);

//Get pointer to file
$fp = fopen('/path/to/file', 'rb');
fpassthru($fp);

function shutdown() {
  $status = connection_status();

  //A connection status of 0 indicates no premature end of script
  if($status == 0){
    //Do whatever to increment the counter for the file.
  }
}
>?

显然有改进的方法,所以如果您需要更多细节或其他行为,请告诉我!

I implemented a similar solution on a file hosting website.

What you want to do is use the register_shutdown_function callback that allows you to detect the end of execution of a php script regardless of the outcome.

Then you want to have your file in a non-web accessible location on your server(s), and have your downloads go through php: idea being that you want to be able to track how many bytes have been passed to the client.

Here's a basic way of implementing (eg:)

<?php
register_shutdown_function('shutdown', $args);

$file_name = 'file.ext';
$path_to_file = '/path/to/file';
$stat = @stat($path_to_file);

//Set headers
header('Content-Type: application/octet-stream');
header('Content-Length: '.$stat['size']);
header('Connection: close');
header('Content-disposition: attachment; filename='.$file_name);

//Get pointer to file
$fp = fopen('/path/to/file', 'rb');
fpassthru($fp);

function shutdown() {
  $status = connection_status();

  //A connection status of 0 indicates no premature end of script
  if($status == 0){
    //Do whatever to increment the counter for the file.
  }
}
>?

There are obviously ways to improve, so if you need more details or another behaviour, please let me know!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文