...

View Full Version : debug download counter



GO ILLINI
01-03-2006, 12:34 AM
count.php

<?php



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

// open for reading
$fp = fopen("$file.dat", "r");
$count = fgets($fp, 1024);
$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

<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.

Velox Letum
01-03-2006, 01:09 AM
"$file.dat"

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

Ex: file_exists($file . '.dat')

GO ILLINI
01-03-2006, 01:11 AM
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

Velox Letum
01-03-2006, 01:22 AM
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.

GO ILLINI
01-03-2006, 01:52 AM
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.

Velox Letum
01-03-2006, 02:19 AM
One, you should move your PHP above any HTML, two, try if ($f == 'ktc1-0') { instead.

GO ILLINI
01-03-2006, 02:59 AM
nope same problem

Velox Letum
01-03-2006, 03:10 AM
I just tried it and it worked...

http://illini.kicks-***.org/games/download/?f=ktc1-0

GO ILLINI
01-03-2006, 03:49 AM
yes but then try it with ?f=blah or no ?f= at all.

Velox Letum
01-03-2006, 05:55 AM
That's because you're only including count.php when the file is ktc1-0.

GO ILLINI
01-03-2006, 01:31 PM
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.

GO ILLINI
01-03-2006, 01:34 PM
Figured it out! This line:

if($f==ktc1-0) {
needed to be
if($f=="ktc1-0") {
i knew it was something with the if...

Velox Letum
01-03-2006, 07:10 PM
...I told that to you a while ago. The problem is you're including count.php ONLY when its ktc1-0.

GO ILLINI
01-03-2006, 09:32 PM
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.

Element
01-03-2006, 09:42 PM
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.

GO ILLINI
01-03-2006, 10:09 PM
well i just used this because i already hade it made. It is a hit counter for a small site i have. Only instead of $file its $page.

Element
01-04-2006, 02:46 AM
Yes, but using this code for every file as it seems, the functions would be in a seperate file, all you would need to do is:



show_url("Kill the Clown 1.0", "http://example.com/downloads/ktc1.0.exe");


or whatever for each download or even link. Because it will go to jump.php and then count it, then go to the URL you put in the function, whether it be the direct download, or a download php script.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum