I have created a simple php download counter, which upon clicking the download link, captures and saves details like ip, file-name, no of times the download has been made, etc. Everything works fine so far. Counter also gets incremented for each download made, but the problem pops up when one uses IDM (or similar download managers); then the counter gets incremented by thrice for each download!

The code I’m using looks like this (on WordPress environment) -

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..
                // 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..
                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');

So the main problem is that the counter gets incremented by twice or thrice if one uses a download manager like IDM. I don’t know what I’m doing wrong here. Also, I’m a php newbie.

Read more here: download counter increases by thrice when using a download manager like IDM


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , , , ,

Wordpress related questions and answers: