bookmark - Make Your Own Very Simple Counter Using PHP!

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.
bookmark - Make Your Own Very Simple Counter Using PHP!  
    
free web hosting
 
Hi!! I'm going to show you how to make your own counter useing php!! :) It's really easy and you woun't have to keep seaching the net for free and bannerless counters.
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.
[post="3943"]<{POST_SNAPBACK}>[/post]


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   

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.

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.
[post="3949"]<{POST_SNAPBACK}>[/post]


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   


But if you substitute the .txt file with a php file is't better?like this

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   

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.

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.
[post="4056"]<{POST_SNAPBACK}>[/post]


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.
[post="4380"]<{POST_SNAPBACK}>[/post]


We're DYI guys, we want to write our own scripts :)

Mon Oct 4, 2004    Reply    New Discussion   

Why search or write you own counter ? if you want an easy way and a ads-less counter, just go to your astahost control panel, under Preinstalled Scripts / CGI Center / Counter, you can choose between 35 diferent types of counters and configure almost anything. After you choose your desired counter, press preview to see it how it's going to be and if you like, press make html and it will write a code to insert in your page.

Greets Deivid

Mon Oct 4, 2004    Reply    New Discussion   

Why don't you use a beautiful flash counter connected with a php code. An example can be downloaded from flashkit.com tutorials.

Mon Oct 4, 2004    Reply    New Discussion   

I know a very good free script named EliteStats.
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   

I personally use and would highly recommend Statcounter, a free counter tracking service. It's so much more powerful than other free counters with its advanced visitor reporting and more.

Fri Oct 8, 2004    Reply    New Discussion   

As I said in the other Forum I have also used statcounter and suggest you at least try it. It is ad free and u have the option to make it invisible or give it a range of colours. You can also with the one acount use it for multiple sitesand pages.

Wed Oct 13, 2004    Reply    New Discussion   

ok I use the Mysql database to store the counter results. coz i have a database maintained already for the site...
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   

@Darren : seems to be interesting from what you say. I will give statcounter a try, and will compare to astahost's one. The one from astahost is also really impressive, I like it. Besides that I forgot my statcounter's password, and I am still waiting for the mail with it.
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   

Not too bad, it's a pretty simple counter, but it get's the job done.
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   

Quickly Post to Make Your Own Very Simple Counter Using PHP!  w/o signup Share Info about Make Your Own Very Simple Counter Using PHP!  using Facebook, Twitter etc. email your friend about Make Your Own Very Simple Counter Using PHP! Print
Reply / Comment Ask a Question? Share / Bookmark E-Mail a Friend Print


(4) How To Create A PHP Based Hit Counter With MySQL  How To Create A PHP Based Hit Counter With MySQL