0

I had a MySQL Download counter previously "working" a few months ago and all of a sudden it has stopped working, It was recording (individual cydia downloads) to the database then posting it to the main webpage with Stats. I've gone through all the code and files, over and over again. Over 24Hours digging and it has still not been solved. If i link the files or post the text "on Here" Would someone please help me.

CONNECT.php

 <?php
    $server = "localhost"; 
    $user = "root";
    $password = "PASSWORD";
    $database = mysql_connect ($server, $user, $password); 
    mysql_select_db("DATABASE_NAME", $database); `
?>

COUNTER.php

<?php

include("connect.php");

$filename = mysql_real_escape_string($_GET['file']);

$path = $_SERVER['DOCUMENT_ROOT']."/"; 

$fullPath = $path.$filename; 

$filetypes = array("deb", "zip");

if (!in_array(substr($filename, -3), $filetypes)) {
    echo "Invalid download type.";
    exit;
}

if ($fd = fopen ($fullPath, "r")) {
    $result = mysql_query("SELECT COUNT(*) AS countfile FROM download
    WHERE filename='" . $filename . "'");
    $data = mysql_fetch_array($result);
    $q = "";

    if ($data['countfile'] > 0) {
        $q = "UPDATE download SET dldate = NOW()+INTERVAL +6 HOUR, stats = stats + 1 WHERE
        filename = '" . $filename . "'";
    } else {
        $q = "INSERT INTO download (filename, dldate, stats) VALUES
        ('" . $filename . "',NOW()+INTERVAL +6 HOUR, 1)"; /* +6 = UK Timezone */
    }
    $statresult = mysql_query($q);

    $fsize = filesize($fullPath);
    $path_parts = pathinfo($fullPath);

    header("Content-type: application/octet-stream");
    header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
    header("Content-length: $fsize");
    header("Cache-control: private"); 
    while(!feof($fd)) {
        $buffer = fread($fd, 2048);
        echo $buffer;
    }
}
fclose ($fd);
exit;

?>

INDEX.html

<div class="downloads">Downloads: 

<?PHP

include("connect.php");

$query = "SELECT stats FROM download WHERE filename = 'deb/com.icon.deb'";

$result = mysql_query($query);

while ($row = mysql_fetch_array($result)) {

echo $row[0];
}
?>
 </div>
</div>
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
  • Without any codes, or relevant infos how do you think we can help even if we want to? – Kishor Jun 26 '15 at 11:33
  • Tried to add code but website wouldn't let me....... – SketchyJeff Jun 26 '15 at 11:46
  • @Kishor Had issues, so left a link. – SketchyJeff Jun 26 '15 at 11:56
  • If you can, you should [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) [statements](http://php.net/manual/en/pdo.prepared-statements.php) instead, and consider using PDO, [it's really not hard](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Jun 26 '15 at 12:50
  • Since it suddenly stopped working are you getting any errors in the error log? You're not checking for errors in your code or with your queries at all. Is it possible that PHP was upgraded and you've been bitten by the deprecation of the `mysql_` API? – Jay Blanchard Jun 26 '15 at 12:54
  • @JayBlanchard Cheers, getting me off the broken track, i had tried mysqli but that also failed but looked at apache2 log and found this " [Fri Jun 26 14:06:34.188379 2015] [:error] [pid 5213] [client IPADDRESS:PORT] PHP Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /var/www/index.php on line 95 ---> Line 95 on the html/php page is" while ($row = mysql_fetch_array($result)) { " – SketchyJeff Jun 26 '15 at 13:10
  • That means there is an error with your query. – Jay Blanchard Jun 26 '15 at 13:11
  • @JayBlanchard Still not got anywhere, just over 32 hours of trying. Lets hope tomorrow gets me somewhere, cheers for the info. – SketchyJeff Jun 26 '15 at 16:59
  • Start with the filename - check the slash especially. – Jay Blanchard Jun 26 '15 at 17:00
  • Also tried that, ( tried removing the slash and adding a slash e.g. "/deb/com.icon.deb" "deb/com.icon.deb" – SketchyJeff Jun 26 '15 at 17:08
  • Just deleted Everything off my server and left myself with only the files & folders i need for the Supposed counter to work.... Nope! still doesn't work with those 3 .php files and the .deb file. I'll be here all night and tomorrow so if anyone else has got an idea, Please share. – SketchyJeff Jun 26 '15 at 17:29

0 Answers0