【问题标题】:download counter increases by thrice when using a download manager like IDM使用 IDM 之类的下载管理器时,下载计数器增加了三次
【发布时间】:2014-06-27 12:46:44
【问题描述】:

我创建了一个简单的 php 下载计数器,单击下载链接后,它会捕获并保存诸如 ip、文件名、下载次数等详细信息。到目前为止一切正常。每次下载时计数器也会增加,但是当使用 IDM(或类似的下载管理器)时会弹出问题; 然后每次下载计数器都会增加三次!

我使用的代码如下所示(在 WordPress 环境中)-

global $wpdb;

            $db_table_name = $wpdb->prefix. 'test_downloads_info';              
            $sql = "SELECT download_count FROM $db_table_name WHERE download_name = %s";
            $result = $wpdb->get_row($wpdb->prepare($sql, $download_name), ARRAY_A);

            // If the row fetched has values..
            if(!empty($result) && !empty($result['download_count'])){

                // Increment the counter by one..
                $download_count = $result['download_count'] + 1;
                // And update the corresponding row..
                $update_result = $wpdb->update($db_table_name, array('download_ip'=> $download_ip, 'download_count'=> $download_count, 'download_date'=> $download_date), array('download_name'=> $download_name));

            }

            // Otherwise..
            else{

                // Insert the new records..
                $insert_result = $wpdb->insert($db_table_name, array('download_name'=> $download_name, 'download_url'=> $download, 'download_ip'=> $download_ip, 'download_count'=> $download_count, 'download_date'=> $download_date), array('%s', '%s', '%s', '%d', '%s'));

            }               

            /**
            * Prepare to force download the requested file
            */

            // Required for IE..
            if(ini_get('zlib.output_compression'))
                ini_set('zlib.output_compression', 'Off');

            // Send all the needed headers for download prompting.. 
            header('Pragma: public');
            header('Expires: 0');
            header('Cache-Control: must-revalidate; post-check=0, pre-check=0');
            header('Cache-Control: private', false);
            header('Content-Type: application/pdf');
            header("Content-Disposition: attachment; filename=\"". basename($download). "\"");
            header('Content-Transfer-Encoding: binary');
            /*header('Content-Length: '. filesize($download));*/
            header('Connection: close');
            readfile($download);
            exit();         

        }

所以主要问题是如果使用 IDM 之类的下载管理器,计数器会增加两倍或三次。我不知道我在这里做错了什么。另外,我是php新手。

【问题讨论】:

  • 我认为正在发生的事情是,下载管理器站点使用到不同服务器的多个连接来下载相同的文件以提高速度,从而增加使用的每个服务器的计数器。我已经用谷歌搜索了您的问题,我发现的唯一可能有帮助的内容可以在此页面上找到 board.phpbuilder.com/… - 您可以使用我使用的关键字进行进一步搜索 @987654323 @ 或您认为合适的其他人。

标签: php wordpress download counter


【解决方案1】:

IDM 通过请求同一文件的不同部分来并行下载。

您应该尝试检查$_SERVER['HTTP_RANGE'] 变量是否存在,如果存在则不要增加您的计数器。类似 IDM 的软件或浏览器使用此变量来恢复下载。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-15
    • 1970-01-01
    • 1970-01-01
    • 2016-01-06
    • 2018-06-10
    相关资源
    最近更新 更多