php - download counter increases by thrice when using a download manager like IDM -
i have created simple php download counter, upon clicking download link, captures , saves details ip, file-name, no of times download has been made, etc. works fine far. counter gets incremented each download made, problem pops when 1 uses idm (or similar download managers); then counter gets incremented thrice each download!
the code i'm using looks (on wordpress environment) -
global $wpdb; $db_table_name = $wpdb->prefix. 'test_downloads_info'; $sql = "select download_count $db_table_name download_name = %s"; $result = $wpdb->get_row($wpdb->prepare($sql, $download_name), array_a); // if row fetched has values.. if(!empty($result) && !empty($result['download_count'])){ // increment counter one.. $download_count = $result['download_count'] + 1; // , update 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 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 force download requested file */ // required ie.. if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'off'); // send needed headers 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(); }
so main problem counter gets incremented twice or thrice if 1 uses download manager idm. don't know i'm doing wrong here. also, i'm php newbie.
idm work requesting different part of same file parallelize download.
you should try check if $_server['http_range']
variable present, , not increment counter if is. variable used idm-like software, or browser resume download.
Comments
Post a Comment