Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts

    debug download counter

    count.php
    PHP Code:
    <?php 



    if(file_exists("$file.dat")) { 

    // open for reading 
    $fp fopen("$file.dat""r"); 
    $count fgets($fp1024); 
    $count++; 
    fclose($fp); 
    echo 
    "There have been $count total downloads of this file."
    // open for writing 
    $fp fopen("$file.dat""w"); 
    fwrite($fp$count); 
    fclose($fp); 

    } else { 

    // create a new file 
    $fp fopen("$file.dat""w"); // open for writing 
    fwrite($fp"1"); 
    echo 
    "There has only been one download.";
    fclose($fp); 


    ?>
    index.php
    PHP Code:
    <html>
    <head>
    <title>Download</title>



    </head>
    <body>
    <h2>Downloads</h2>

    <?php
    if($f==ktc1-0) {
    $file "ktc1.0";
    $name "Kill the Clown 1.0";
    include(
    "count.php");
    }
    else {
    ?>
    Im sorry there was some sort of error with the download<br>
    <?php
    if($f=="") {
    echo(
    "You didnt enter anything in");
    }
    else {
    echo(
    $f);
    echo(
    " is not a valid file");
    }
    }
    ?>
    It alwayse does the if. Even if $f isnt anything. So it adds one to the file even though no file was specified. Any help?
    EDIT: P.S. it is passed through a static link on the files page not a form in the url(?f=file)
    I havent actually made the download part yet i want to get this first.
    Last edited by GO ILLINI; 01-03-2006 at 12:36 AM.
    Why not thank me?

    http://adamsworld.name

  • #2
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    "$file.dat"

    This won't work correctly. Use $file . '.dat' instead when opening the file.

    Ex: file_exists($file . '.dat')
    "$question = ( to() ) ? be() : ~be();"

  • #3
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts
    OK, but that still doesnt wxplain why it automaticly doe the if. But thanks.
    http://illini.kicks-***.org/games/download/ to see for yourself
    man that censoring... its a s s
    Why not thank me?

    http://adamsworld.name

  • #4
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If it doesn't have the correct filename to detect as already existing, it'll attempt to create it. The way you have the filename written out will not work. I gave the solution above. $file may equal ktc-1.0, but $file isn't being used correctly.
    "$question = ( to() ) ? be() : ~be();"

  • #5
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts
    Im sorry i didnt specify...
    I ment the if in index.php it still includes the count page even when f is wrong/not there. I changed all the filename problems with what you gave me.
    Why not thank me?

    http://adamsworld.name

  • #6
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    One, you should move your PHP above any HTML, two, try if ($f == 'ktc1-0') { instead.
    "$question = ( to() ) ? be() : ~be();"

  • #7
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts
    nope same problem
    Why not thank me?

    http://adamsworld.name

  • #8
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I just tried it and it worked...

    http://illini.kicks-***.org/games/download/?f=ktc1-0
    "$question = ( to() ) ? be() : ~be();"

  • #9
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts
    yes but then try it with ?f=blah or no ?f= at all.
    Why not thank me?

    http://adamsworld.name

  • #10
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That's because you're only including count.php when the file is ktc1-0.
    "$question = ( to() ) ? be() : ~be();"

  • #11
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts
    yes thats what i want... But it includes it anyway. Its like the if isnt even there. because $file is set even if f isnt.
    Why not thank me?

    http://adamsworld.name

  • #12
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts
    Figured it out! This line:
    Code:
    if($f==ktc1-0) {
    needed to be
    if($f=="ktc1-0") {
    i knew it was something with the if...
    Why not thank me?

    http://adamsworld.name

  • #13
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ...I told that to you a while ago. The problem is you're including count.php ONLY when its ktc1-0.
    "$question = ( to() ) ? be() : ~be();"

  • #14
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts
    I only want it to open the counter when the file is actually on my list. But it works fine now. Thanks for the help.
    Why not thank me?

    http://adamsworld.name

  • #15
    Regular Coder Element's Avatar
    Join Date
    Jul 2004
    Location
    Lynnwood, Washington, US
    Posts
    855
    Thanks
    2
    Thanked 2 Times in 2 Posts
    This is why I made my flat file url counter in the PHP snippet section, it uses two functions, one for displaying the link, and the other to count the hit. If the file has never been shown on the site using show_url("Site name", "URL") then it will never let a person count a hit for something that hasn't been made.

    And that script will work for you, becuase all you would have to do is set the URL to the link page, which could then by default set the header to forward to the download page passing the file name over.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •