Download File Help

Discussion in 'PHP' started by imchandan, Apr 23, 2008.

  1. #1
    Hi All,
    On first page of my site i display the softwares which has top rank...
    when anyone download the file, the rank of file is incremented by one(i have set download.php that way)....
    now the problem is :- if anyone is using some download manager or something(I use IDM as download manger), then it download the file in parts , say 5 parts.. then 5 connection to server is made... and rank is incremented by 5... which is not right..
    please suggest me something...
    heres a part of my download.php code which updates rank:-

    $id = trim($_REQUEST['f']);
    $query="select rank from softwares where file_name = '$id'";

    $rt=mysql_query($query);

    $nt=mysql_fetch_array($rt); $current_rank = $nt['rank'];
    if(!empty($current_rank)){
    //then execute other query to update the things
    $current_rank = $current_rank + 1;
    $query="update softwares set rank = '$current_rank' where file_name = '$id'";
    $rt=mysql_query($query);
    mysql_close($link);
    }
     
    imchandan, Apr 23, 2008 IP
  2. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #2
    If there exist 5 connections, then it should count as 5 downloads.

    There is no way you can know if two connections are related, unless you have a hash system (similar to torrent sites) where you give each user a specific hash to which only they can use to download (where you later can check each hash).

    I would also recommend:

    $id = mysql_real_escape_string(trim($_REQUEST['f']));

    To avoid MySQL injection.

    Peace,
     
    Barti1987, Apr 23, 2008 IP
  3. imchandan

    imchandan Guest

    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #3
    hey azizny,
    thanks for your reply... actually i already use SQL injection prevention.. thanks anyways.. let's come to main topic... i am thinking something, please stop me if i am wrong..if a specific IP calles a file say file1.zip then we can store it in session like $_SESSION[IP][file_downloaded] = file1.zip
    ..if second time download.php is called from same IP for same file1.zip then file1.zip should be dowloaded but rank updation query will not be executed...
    do think i am going on right track ?
     
    imchandan, Apr 23, 2008 IP
  4. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #4
    You could, but you will not count those people who are downloading from cafe,companies,schools and other networks with the same IP.

    Peace,
     
    Barti1987, Apr 23, 2008 IP