Welcome Guest ( Log In | Register )



4 Pages V   1 2 3 > »   
Reply to this topicStart new topic
> Make Your Own Very Simple Counter Using PHP!
websaint
post Sep 28 2004, 08:58 PM
Post #1


Member [ Level 1 ]
Group Icon

Group: [HOSTED]
Posts: 43
Joined: 15-September 04
Member No.: 610



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

This post has been edited by miCRoSCoPiC^eaRthLinG: Jan 27 2006, 07:23 AM
Go to the top of the page
 
+Quote Post
qwijibow
post Sep 29 2004, 03:23 PM
Post #2


Way Out Of Control - You need a life :)
Group Icon

Group: Members
Posts: 1,366
Joined: 14-September 04
From: Nottingham England
Member No.: 570



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.
Go to the top of the page
 
+Quote Post
Hercco
post Sep 29 2004, 05:26 PM
Post #3


Super Member
Group Icon

Group: Members
Posts: 595
Joined: 4-September 04
Member No.: 228



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.
Go to the top of the page
 
+Quote Post
qwijibow
post Sep 30 2004, 02:56 PM
Post #4


Way Out Of Control - You need a life :)
Group Icon

Group: Members
Posts: 1,366
Joined: 14-September 04
From: Nottingham England
Member No.: 570



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.
Go to the top of the page
 
+Quote Post
k22
post Sep 30 2004, 04:03 PM
Post #5


Advanced Member
Group Icon

Group: Members
Posts: 165
Joined: 22-September 04
From: IS - IT - US - BE
Member No.: 804



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

?>

Go to the top of the page
 
+Quote Post
sha
post Oct 4 2004, 02:02 PM
Post #6


Newbie [ Level 2 ]
Group Icon

Group: Members
Posts: 18
Joined: 4-October 04
Member No.: 1,030



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.
Go to the top of the page
 
+Quote Post
Hercco
post Oct 4 2004, 02:15 PM
Post #7


Super Member
Group Icon

Group: Members
Posts: 595
Joined: 4-September 04
Member No.: 228



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
Go to the top of the page
 
+Quote Post
deivid
post Oct 4 2004, 05:17 PM
Post #8


Member - Active Contributor
Group Icon

Group: Members
Posts: 96
Joined: 15-September 04
Member No.: 588



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
Go to the top of the page
 
+Quote Post
antitoxic
post Oct 4 2004, 05:43 PM
Post #9


Member [ Level 1 ]
Group Icon

Group: Members
Posts: 46
Joined: 20-September 04
Member No.: 757



Why don't you use a beautiful flash counter connected with a php code. An example can be downloaded from flashkit.com tutorials.
Go to the top of the page
 
+Quote Post
sohahm
post Oct 6 2004, 05:13 PM
Post #10


Newbie [ Level 2 ]
Group Icon

Group: Members
Posts: 13
Joined: 6-October 04
Member No.: 1,036



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
Go to the top of the page
 
+Quote Post

4 Pages V   1 2 3 > » 
Reply to this topicStart new topic

Collapse

> Similar Topics

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


 



- Lo-Fi Version Time is now: 14th October 2008 - 10:18 AM