How do you make your own PHP Web Counter?
Announcement
Collapse
No announcement yet.
PHP Web Counter
Collapse
X
-
Here is a simple download counter I use.
Could be used as a webpage counter.
I use a link like
<a href="download.php?this_file=file1">file one</a>
PHP Code:<?
/* Count the number of times a file was downloaded */
function count_hits()
{
global $this_file;
$cfile = "$this_file.php".".dat";
$fh = fopen($cfile,"r+");
if(!$fh)
{
die("<br>Failed to open file <i>$cfile</i>.");
}
$s = fgets($fh,6);
$count = (int) $s;
$count = $count + 1;
$count = str_pad($count,6);
rewind($fh);
fwrite($fh,$count);
fclose($fh);
header("location:my/webur/of a file/to download/")
or die ("error1");
}
/* Notify me when a file is downloaded. */
function mail_this()
{
global $this_file;
$to = "";
$subject ="Download complete";
$message = "Some one downloaded $this_file";
mail($to,$subject,$message);
}
switch($this_file)
{
case file1:
$this_file="file1";
mail_this();
count_hits();
break;
default:
echo "default error";
break;
}
?>
Comment
-
using what's above you will need to create a file1.php.dat
make sure to chmod 777 so it will have write access.
then point a link to the download.php.
To view the number of downlads just include the file1.php.dat.
e.g.
PHP Code:<?
include("file.php.dat");
?>
Comment
-
Related Topics
Collapse
-
by voygerhi all got few little problem hope you can help solved
the download files count don't work does not Matter at many time i download the file it shows one views
thanks for...-
Channel: Support Issues & Questions
Tue 13 Mar '18, 1:06pm -
Comment