The Wayback Machine - https://web.archive.org/all/20041208072458/http://www.freescripts.com:80/text-counter.php

Free Scripts
 
Banner Ads
Chat
Form Processor
GuestBook
MailFile
PostCard
 
Free Snippets
 
Cookies
Header/Footer
Random Text
Text Counter
 
Scripts Directory
 
ASP
ASP.NET
Java
Javascript
Perl
PHP
Python
XML
 
Misc.
 
Hosting Directory
ASP & PHP Tutorials
Barcelona Property
Buy UK Traffic
PHP Classes
Meta Language
Magic & Mythology
Car Insurance Quotes
Concert Tickets
Hosting Secrets
Payday Loan
Blog Rankings
Add Listing
Contact Us
 
   





Description

This script will include a simple text counter on the page of your choice. The scripts do not require a database of any kind.

Text Counter in PHP

Just include the following code where you want to include a file in a .php file.
<?
$counter_file = ("counter.txt");   //file where count is stored
$visits = file($counter_file);    //puts the count in a variable
$visits[0]++;               //add 1 to the counter

$fp = fopen($counter_file , "w");           //open the file for write
fputs($fp , "$visits[0]");           //write the new value to the file

fclose($fp);            //close the file

print $visits[0] . " visitors so far.";
?>

Text Counter in ASP

Use the following code to include a counter in your page in ASP. Create the file counter.txt with nothing but the number 0 in it before you try to use the following script

<%
Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.OpenTextFile("C:\path\to\counter.txt")

oldNumber = CLng(oFile.ReadLine)   'read the current count out of the file

oFile.Close    'close the file because we're done reading it

oldNum = oldNum + 1     'add 1 to the current counter number

Set oFile = oFSO.OpenTextFile("C:\path\to\counter.txt",2,true)

oFile.WriteLine(oldNum)           'write the new counter value to file
oFile.Close                    'close the file

Response.Write(oldNum & " visitors so far.")
%>

Copyright © 1996 - 2003 JumpBug Enterprises
Read our Privacy Statement
Read our License Agreement