PHP Counter
Moderator: General Moderators
PHP Counter
Hi .
I've been looking everywhere for a good php counter..
I'm looking for a counter..that users can view the counter from a diffrent page..
anyone knows how to make a counter like this ?
index.php?action=downloadfile&filename=
I mean like , include.
please.
thanks..
I've been looking everywhere for a good php counter..
I'm looking for a counter..that users can view the counter from a diffrent page..
anyone knows how to make a counter like this ?
index.php?action=downloadfile&filename=
I mean like , include.
please.
thanks..
To do something like that, you'll most likely need to route all downloads through one file (like download.php). If you pass that file a filename like you did in your example, download.php can then log the fact that it was downloaded. If you store that in a database, it'll be easy to retrieve the download counts for each file.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Or you could guide him in the right direction to code it himself....rehfeld wrote:hotscripts.com
-------------------
Play around in mysql a bit and get the feel for databases, then go to http://php.net and search for "mysql".... look at some of the functions you find.
So you could do something like this:
download.php
Code: Select all
<?php
$file=$_GET['file'];
$file=addslashes($file);
/* Do a mysql query here to Insert / update something to show that some one has downloaded $file */
header("location:http://yoursite.com/downloads/$file");
?>or instead of fowarding to the file:
Code: Select all
<?php
header('Content-type: application/x-msdownload');
output("downloads/" . $file . ".exe");
?>- asi0917
- Forum Commoner
- Posts: 41
- Joined: Thu Nov 25, 2004 10:37 am
- Location: Shoreline, Washington
- Contact:
for page view see this
http://www.spoono.com/php/tutorials/tutorial.php?id=4
http://www.spoono.com/php/tutorials/tutorial.php?id=4
Ok i've got it working.
http://www.oktober.co.il/rafi/files/ind ... e=test.ace
and the counter works good too..(counter.dat)
i want to to count more files though..
like ?name=bleh.zip..i want the counter to be like counter2.txt..
is it possible to have seprate download counters?
thanks alot..
here's the code for index.php..
<?php
// download.php?name=filename
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=".$_GET["name"]);
@readfile('./'.$_GET['name']);
if(file_exists("counter.dat"))
{
$exist_file = fopen("counter.dat", "r");
$new_count = fgets($exist_file, 255);
$new_count++;
fclose($exist_file);
print("$new_count people have visited this page");
$exist_count = fopen("counter.dat", "w");
fputs($exist_count, $new_count);
fclose($exist_count);
}
else
{
$new_file = fopen("counter.dat", "w");
fputs($new_file, "1");
print("1 person have visited this page");
fclose($new_file);
}
?>
http://www.oktober.co.il/rafi/files/ind ... e=test.ace
and the counter works good too..(counter.dat)
i want to to count more files though..
like ?name=bleh.zip..i want the counter to be like counter2.txt..
is it possible to have seprate download counters?
thanks alot..
here's the code for index.php..
<?php
// download.php?name=filename
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=".$_GET["name"]);
@readfile('./'.$_GET['name']);
if(file_exists("counter.dat"))
{
$exist_file = fopen("counter.dat", "r");
$new_count = fgets($exist_file, 255);
$new_count++;
fclose($exist_file);
print("$new_count people have visited this page");
$exist_count = fopen("counter.dat", "w");
fputs($exist_count, $new_count);
fclose($exist_count);
}
else
{
$new_file = fopen("counter.dat", "w");
fputs($new_file, "1");
print("1 person have visited this page");
fclose($new_file);
}
?>
no we can read it, just the
Code: Select all
tags makes it easier to read- dull1554
- Forum Regular
- Posts: 680
- Joined: Sat Nov 22, 2003 11:26 am
- Location: 42:21:35.359N, 76:02:20.688W
Code: Select all
<?php
// download.php?name=filename
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=".$_GET["name"]);
@readfile('./'.$_GET['name']);
if(file_exists("counter.dat"))
{
$exist_file = fopen("counter.dat", "r");
$new_count = fgets($exist_file, 255);
$new_count++;
fclose($exist_file);
print("$new_count people have visited this page");
$exist_count = fopen("counter.dat", "w");
fputs($exist_count, $new_count);
fclose($exist_count);
}
else
{
$new_file = fopen("counter.dat", "w");
fputs($new_file, "1");
print("1 person have visited this page");
fclose($new_file);
}
?>