Jump to content
xisto Community
websaint

Make Your Own Very Simple Counter Using PHP!

Recommended Posts

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:

<?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:

<p>Number of guests visiting my site: <? include('alle.txt'); ?>.</p>

That's it. I hope you'll find the script useful! :)
Edited by miCRoSCoPiC^eaRthLinG (see edit history)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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_SNAPBACK}>


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.

Share this post


Link to post
Share on other sites

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_SNAPBACK}>


you misunder stand my meaning.......

 

i mean someone could replace

 

<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.

Share this post


Link to post
Share on other sites

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

<?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<?phpNV=34?>

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

<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_SNAPBACK}>


And that would accomplish what?

 

 

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_SNAPBACK}>


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

Share this post


Link to post
Share on other sites

Why search or write you own counter ? if you want an easy way and a ads-less counter, just go to your Xisto 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

Share this post


Link to post
Share on other sites

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 Ahmedsohail4@msn.com

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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...

Share this post


Link to post
Share on other sites

@Darren : seems to be interesting from what you say. I will give statcounter a try, and will compare to Xisto's one. The one from Xisto 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.YordanOK, Darren, your are right, statcounter is really great. Their counters are not so nice as Xisto 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 Xisto counter.So, if you want something easy to implement, very nice, with a comfortable menu-diriven settings, use Xisto's cpanel one. If you want something simple, which works on any site including your PC, use statcounter.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.