IPB

Welcome Guest ( Log In | Register )



Tags
This content has not been tagged yet
 
Reply to this topicStart new topic

Visitors Counter

, With PHP (no MySQL needed!)


FaLgoR
no avatar
Super Member
*********
Group: Members
Posts: 217
Joined: 2-January 05
Member No.: 3,084



Post #1 post Feb 16 2005, 11:15 PM
Well, here we will make an hit counterusing php and an *.txt file. This script is so simple, but very usefull. First, le'ts make an file called counter.php, with the following codes inside:

CODE

<?
$file = 'counter.txt'; // this is the file where the number of visitors will be written
$fopen = fopen("$file", "r"); // open the text file
$count = fread($fopen, 1024); // read the text file
fclose($fp); // close the text file
$count = $count + 1; // add one more hit
echo "$count"; // print the number
$fopen = fopen("counter.txt", "w"); // open the file again
fwrite($fp, $count); // write the new number
fclose($fp); // close the file
?>


That's all, it must e working fine (I'm using it :]). To show the number of hits on your site and add the counter, just insert this line where the counter will be:
CODE

<? include("counter.php"); ?>

It will show the visitors AND add the counter.

Problems, just post ;D


----------------------------- Edited -------------------------------------
I forgot, youll have to make an blank file called counter.txt. Have fun =P
Go to the top of the page
+Quote Post
no9t9
no avatar
Privileged Member
*********
Group: Members
Posts: 773
Joined: 4-November 04
Member No.: 2,118



Post #2 post Feb 17 2005, 01:53 AM
I also used a script like this for counting but I found that it wasn't really enough information. It would be more accurate to count per session using cookies or something. I did a counter with cookies but then I wanted even more information like referrer, time spent, etc. I kind of gave up on this and just joined statcounter.com. They do it for you and you don't have to waste time making the program.

the only problem with statcounter is that it only shows the last 100 page loads for free accounts. But, I find the information very useful.

O, thanks for putting up the code. It actually is a good counter if you aren't worried about analyzing traffic. Many people will undoubtedly find it useful.
Go to the top of the page
+Quote Post
leiaah
no avatar
Super Member
*********
Group: Members
Posts: 436
Joined: 21-January 05
From: Koronadal City, Philippines
Member No.: 3,358



Post #3 post Feb 17 2005, 01:05 PM
HOW ABOUT THIS?


------------------TO INCREMENT HITS BY 1------------------

<?php
$filename= "hits.txt" ;
$fd = fopen ($filename , "r") or die ("PHP script cant open $filename") ;
$fstring = fread ($fd , filesize ($filename)) ;
echo "$fstring" ;
fclose($fd) ;

$fd = fopen ($filename , "w") or die ("PHP script cant open $filename") ;
$fcounted = $fstring + 1 ;
$fout= fwrite ($fd , $fcounted ) ;
fclose($fd) ;
?>

OR

<?php
$filename = "hits.txt" ;

$file = file($filename);
$file = array_unique($file);
$hits = count($file);
echo $hits;

$fd = fopen ($filename , "r");
$fstring = fread ($fd , filesize ($filename)) ;
fclose($fd) ;
$fd = fopen ($filename , "w");
$fcounted = $fstring."\n".getenv("REMOTE_ADDR");
$fout= fwrite ($fd , $fcounted );
fclose($fd);
?>


HOPE THIS HELPS.
Go to the top of the page
+Quote Post
FaLgoR
no avatar
Super Member
*********
Group: Members
Posts: 217
Joined: 2-January 05
Member No.: 3,084



Post #4 post Feb 17 2005, 04:48 PM
QUOTE(no9t9 @ Feb 16 2005, 10:53 PM)
I also used a script like this for counting but I found that it wasn't really enough information.  It would be more accurate to count per session using cookies or something.  I did a counter with cookies but then I wanted even more information like referrer, time spent, etc.  I kind of gave up on this and just joined statcounter.com.  They do it for you and you don't have to waste time making the program. 

the only problem with statcounter is that it only shows the last 100 page loads for free accounts.  But, I find the information very useful.

O, thanks for putting up the code. It actually is a good counter if you aren't worried about analyzing traffic.  Many people will undoubtedly find it useful.
[right][snapback]51325[/snapback][/right]


I am not showing an page tracker, this is just a hit counter! =/
Go to the top of the page
+Quote Post
alexia
no avatar
Super Member
*********
Group: Members
Posts: 310
Joined: 9-February 05
From: Italian
Member No.: 3,677



Post #5 post Feb 27 2005, 09:59 PM
Nice Code
You can Make DB (FlatFile) on your host with 755 PM Access For Rewrite on
and then make on php page and when user view this page the page input the 1 to file
for example if in file is 1
the php page get File data and add one to it and rewrite to file
thats all
u can find many CMs for this Post in google or hotscripts or Script Websites
Go to the top of the page
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   13 KooL 1,906 31st August 2004 - 10:08 AM
Last post by: Too_Hot
No new   19 dask 1,446 4th August 2004 - 05:01 AM
Last post by: zyklon
No New Posts   2 gpinvest 963 19th July 2006 - 12:10 PM
Last post by: Florisjuh
No New Posts   6 KooL 574 21st September 2004 - 11:13 PM
Last post by: odomike
No New Posts   1 tomecki 1,188 31st August 2004 - 08:52 PM
Last post by: neeki4444
No new   15 psp-playstation 1,020 3rd September 2004 - 12:42 AM
Last post by: annylei
No new   15 -prodigy- 1,946 27th February 2005 - 10:22 PM
Last post by: alexia
No New Posts   5 blackhawk 609 31st August 2004 - 01:13 PM
Last post by: Spectre
No New Posts   2 ZorBiX 543 28th October 2004 - 09:14 AM
Last post by: ZorBiX
No new   34 MercifulFate 4,934 16th March 2005 - 07:26 PM
Last post by: AboveZero
No New Posts   3 outbreak 1,016 8th March 2005 - 10:21 PM
Last post by: Benz1435
No New Posts   4 sithslayer 390 14th December 2008 - 02:29 PM
Last post by: sithslayer
No New Posts   11 illdevilinc 814 10th June 2006 - 08:55 PM
Last post by: illdevilinc
No New Posts   4 Dreamer 382 20th November 2004 - 09:06 PM
Last post by: swanx
No New Posts   2 cragllo 612 3rd January 2009 - 09:04 AM
Last post by: contactskn


 



RSS Open Discussion Time is now: 9th January 2009 - 06:26 AM