Make Your Own Very Simple Counter Using PHP!

Pages: 1, 2, 3, 4
free web hosting

Read Latest Entries..: (Post #35) by rockarolla on Feb 17 2008, 05:00 PM. (Line Breaks Removed)
file based counter may jam - sometimes it wont be able to overwirte the data - when many visitors navigate to your web. The other problem is if you ain't got permissions to open a file on your server...hence host dependent.
Read the FIRST post of this Topic. - Express your Opinion! Contribute Knowledge :-).

Free Web Hosting > Computers & Tech > How-To's and Tutorials > Programming > PHP

Make Your Own Very Simple Counter Using PHP!

websaint
Hi!! I'm going to show you how to make your own counter useing php!! tongue.gif 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! rolleyes.gif

 

 

 


Reply

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.

Reply

Hercco
QUOTE(qwijibow @ Sep 29 2004, 05:23 PM)
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.

 

 

 


Reply

qwijibow
QUOTE(Hercco @ Sep 29 2004, 06:26 PM)
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.

Reply

k22
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

?>


Reply

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.

Reply

Hercco
QUOTE(qwijibow @ Sep 30 2004, 04:56 PM)
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 @ Oct 4 2004, 04:02 PM)
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 wink.gif

Reply

deivid
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

Reply

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

Reply

sohahm
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

Reply

Latest Entries

rockarolla
file based counter may jam - sometimes it wont be able to overwirte the data - when many visitors navigate to your web.

The other problem is if you ain't got permissions to open a file on your server...hence host dependent.


Reply

comkidwizzer3
QUOTE(qwijibow @ Sep 30 2004, 02:23 AM) *
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.



QUOTE(qwijibow @ Oct 1 2004, 01:56 AM) *
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.


A solution to your problem just encode your webpage.

Reply

optiplex
verry good & no mysql !

Reply

livingston
wow a great simple and effective counter.

Reply

warallthetm
Dose this script count page loads or unique ips? I have been searching fo a php script that count's unique visitors and not just page loads. Is there a way to mod this?

Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Pages: 1, 2, 3, 4
Recent Queries:-
  1. how to build a php counter - 0.05 hr back. (1)
  2. a counter in php - 30.87 hr back. (1)
  3. create hit count flash using php - 38.04 hr back. (2)
  4. create website counters using php - 49.96 hr back. (1)
  5. how to make a hit counter for flash videos php - 66.92 hr back. (1)
  6. how to make flash counter - 71.09 hr back. (1)
  7. how to make a counter using php - 73.66 hr back. (1)
  8. how to build a counter in a html page php - 76.47 hr back. (1)
  9. how to make counter flash script - 78.88 hr back. (1)
  10. php counter - 80.43 hr back. (1)
  11. how to make a website counter im php - 89.49 hr back. (1)
  12. website counter php how to make - 89.51 hr back. (1)
  13. make my own hit counter - 100.60 hr back. (1)
  14. php counter fopen disabled - 113.53 hr back. (1)
Similar Topics

Keywords : make, simple, counter, php

  1. How To Create A PHP Based Hit Counter
    With MySQL (2)


      Looking for make, simple, counter, php

Searching Video's for make, simple, counter, php
advertisement




Make Your Own Very Simple Counter Using PHP!



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE