Log in

View Full Version : Download Counter



timROGERS
23-12-2005, 06:29 PM
I've just made this download counter, to make it work, all you have to do is make a blank counter.txt and CHMOD it to 777. This ups the number in counter.txt and then redirects you to the file you wanted to download.


<?php
$filename = "counter.txt"; /* Set variable "$filename" as counter.txt */
$handle = fopen($filename, "r+"); /* Sets the $handle variable to open the "$filename" variable */
$nexturl = "http://www.technoteens.net/Habbox%20Baby.mp3"; /* Sets the URL to go to after counting */
$line = fgets($handle, 20); /* Gets the first line from the file */
$line += 1; /* Increases the line by one */
rewind($handle); /* Goes back to the start of the file */
fwrite($handle, $line); /* Performs the increads */
fclose($handle); /* Closes the file on the server */
header("location: $nexturl"); /* Redirects to the $nexturl file */
?>

Next make a file called redir.php and put the following in it:


<?php $countingfile = "Habbox Baby.mp3"; ?>

Then you can easily make a page that displays the current stats, make a file called display.php, and put in the following contents:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Hit Counter</title>
<style type="text/css">
<!--
body,td,th {
color: #FFFFFF;
}
body {
background-color: #00ccff;
}
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: bold;
}
-->
</style></head>

<body>
<?php include 'redir.php'; ?>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p align="center" class="style1">Hits on <?php echo $countingfile ?><br />
<br />
<center><span class="style1"><?php

// set file to read
$file = 'counter.txt';
// open file
$fh = fopen($file, 'r') or die('Could not load counter.');
// read file contents
$data = fread($fh, filesize($file)) or die('Could not fetch counter contents.');
// close file
fclose($fh);
// print file contents
echo $data;

?></span></center>
</p>
</body>
</html>


If you put all that together into a directory, it will all work well! To view a demo of this in action click here (http://www.tim-rogers.co.uk/hxf/dlm). If you want you can make a full center out of this and you can make it display stats for all of your downloads.

[b]To customize this all you have to do is change the following variables:

$nexturl - Change this to the URL of your download
$countingurl - Make this the name of the file you are counting the hits to

Dan Williamson
23-12-2005, 06:45 PM
Pretty nice :)

I was going too post a download system with a counter built in :)

- Dan

Rix
24-12-2005, 12:35 AM
please do that dan

Dan Williamson
24-12-2005, 12:38 AM
Maybe at like 5am or tomorrow night :)

I'm doing a big layout on Photoshop now.

- Dan

Andie
24-12-2005, 12:44 AM
@Dan: reply to PM dude.

@topic: nice. php never works for me. I do the right stuff, but when i go and click on my index.php in my site file it doesnt work. any tips?

Dan Williamson
24-12-2005, 01:05 AM
@Dan: reply to PM dude.

@topic: nice. php never works for me. I do the right stuff, but when i go and click on my index.php in my site file it doesnt work. any tips?

Maybe. Does your host support PHP?

- Dan

timROGERS
24-12-2005, 09:07 AM
Eactly what I was gonna say Dan :)

Want to hide these adverts? Register an account for free!