|
|
Make Your Own Very Simple Counter Using PHP! | ||
Discussion by websaint with 38 Replies.
Last Update: June 14, 2012, 7:56 pm (View Latest) | Page 1 of 3 pages. | ||
So here comes the script:
CODE
<?php//Simple class for counting visits
//Written by WebSaint
class Teller {
function count() {
$countfile = file("alle.txt");
$count = $countfile[0];
$count= $count + 1;
$fp = fopen("alle.txt","w");
$fw = fwrite($fp,$count);
fclose($fp);
echo $count;
}
}
$obj =& new Teller;
$obj->count();
?>
Then add this to display the number of visitors:
CODE
<p>Number of guests visiting my site: <? include('alle.txt'); ?>.</p>That's it. I hope you'll find the script useful!
Tue Sep 28, 2004 Reply New Discussion
QUOTE (qwijibow)
Good... but you might find others steal your counter if they find it...they will link to your counter script, and store their page cound on your server.
its always good to add some kind of proetection againsed this. a good, but not perfect way is to make sure the referer comes from your own site, and nobody elses.
Well it's impossible to "steal" this. If you include that file from Websaints server the code will be treated as it was run on your server and thus will try to look file alle.txt from your server. If you simply request that file it will only add hits to Websaints counter.
The referer checking would be pointless in this but I'd like comment it a bit in general. People do not seem to know or just forget that nowadays quite many users disable or block referer sending. In certain browsers it is an option and I believe most of the current commercial software firewalls include an option to block them. Not taking this into account can mean that users that do not want to send referers can't use the service at all. For instance one development version of the WordPress blog software required referer sending to make changing it's options possible. The referer checking was simply just for sending the user back to the page where he came from. Other example is a certain torrent site that refuses to work if not getting referer information. They reason is understandable though: there is apparently countless "mirror" sites that are not actual mirrors but simply index their files and points the user to download the .torrents from the original site.
Wed Sep 29, 2004 Reply New Discussion
they will link to your counter script, and store their page cound on your server.
its always good to add some kind of proetection againsed this. a good, but not perfect way is to make sure the referer comes from your own site, and nobody elses.
Wed Sep 29, 2004 Reply New Discussion
QUOTE (Hercco)
Well it's impossible to "steal" this. If you include that file from Websaints server the code will be treated as it was run on your server and thus will try to look file alle.txt from your server. If you simply request that file it will only add hits to Websaints counter.The referer checking would be pointless in this but I'd like comment it a bit in general. People do not seem to know or just forget that nowadays quite many users disable or block referer sending. In certain browsers it is an option and I believe most of the current commercial software firewalls include an option to block them. Not taking this into account can mean that users that do not want to send referers can't use the service at all. For instance one development version of the WordPress blog software required referer sending to make changing it's options possible. The referer checking was simply just for sending the user back to the page where he came from. Other example is a certain torrent site that refuses to work if not getting referer information. They reason is understandable though: there is apparently countless "mirror" sites that are not actual mirrors but simply index their files and points the user to download the .torrents from the original site.
you misunder stand my meaning.......
i mean someone could replace
CODE
<p>Number of guests visiting my site: <? include('alle.txt'); ?>.</p>the include file with a coomplete URL to anouther server. and replace "alle.txt" with a different filename.
Thu Sep 30, 2004 Reply New Discussion
CODE
<?php<?php
$now=fopen("count.php","r+");
while(!feof($now)){
$cont=fgets($now,2);
if ($cont=="N") {
$check=fgets($now,3);
if($check=="V=") {
$nvisit=fgets($now,4);
echo $nvisit;
settype($nvisit,"integer");
$posi=ftell($now);
fseek($now,($posi-2));
fwrite($now,($nvisit+1));
exit;
}
}
}
fclose($now);
?>
and a count.php like this
<?php
NV=34
?>
Thu Sep 30, 2004 Reply New Discussion
Mon Oct 4, 2004 Reply New Discussion
QUOTE (qwijibow)
CODE
<p>Number of guests visiting my site: <? include('alle.txt'); ?>.</p>the include file with a coomplete URL to anouther server. and replace "alle.txt" with a different filename.
And that would accomplish what?
QUOTE (sha)
there are many scripting languages and you can find counter in each. first check which scripting is available on your server and then try to find its script for counter. i reccomond altavista.com rather than google.com for finding free scripts.We're DYI guys, we want to write our own scripts
Mon Oct 4, 2004 Reply New Discussion
Greets Deivid
Mon Oct 4, 2004 Reply New Discussion
Mon Oct 4, 2004 Reply New Discussion
You just have to put its folder in your main directory and include a one line of code in your webpage.
It will display How many visitors are online and complete statistics with IP address.
Sohail Ahmed
sohail4@msn.com
Wed Oct 6, 2004 Reply New Discussion
Fri Oct 8, 2004 Reply New Discussion
Wed Oct 13, 2004 Reply New Discussion
the code is simple just fetch the row with the counter...
and use echo display on the page...
why bother about the security... The data base is secured...
Thu Nov 18, 2004 Reply New Discussion
Yordan
OK, Darren, your are right, statcounter is really great. Their counters are not so nice as astahost ones, and the menus to step inside are not really easy to understand, and I experienced several disconnections in the middle of the process of creationg your counter. But if you want something really simple, without any ads, it's a simple line to be included inside your html source. And it works anywhere, including on your own PC for testing purposes, which is not the case for the astahost counter.
So, if you want something easy to implement, very nice, with a comfortable menu-diriven settings, use astahost's cpanel one. If you want something simple, which works on any site including your PC, use statcounter.
Wed Sep 7, 2005 Reply New Discussion
I've been trying to figure out this one though, how do we make a download counter, that one is a bit harder isn't it? I suppose we'd make a page that would open the file's URL in a redirect, but also add to the counter and direct them to that instead of the counter?
Wed Sep 7, 2005 Reply New Discussion
(4) How To Create A PHP Based Hit Counter With MySQL
|
Index




