Text Counter FAQ

Frequently asked questions about the Text Counter CGI script.

Q1: How do I set up the text counter?

To set up the Text Counter:

  1. Upload the script:
    Upload textcounter.pl to /cgi-bin/
    chmod 755 textcounter.pl
  2. Create counter file:
    echo "0" > counter.txt
    chmod 666 counter.txt
  3. Include in your page:
    <!--#exec cgi="/cgi-bin/textcounter.pl"-->

Q2: Why isn't my counter incrementing?

If your counter isn't incrementing, check these issues:

  1. File permissions: Counter file must be writable (666)
  2. File path: Verify $count_file path is correct
  3. File exists: Ensure counter.txt exists and contains a number
  4. File locking: Check if another process has locked the file

Test by running:

ls -la counter.txt
cat counter.txt
Tip: Some servers require 644 instead of 666 - check with your host.

Q3: How do I reset the counter?

To reset the counter to zero:

  1. Via FTP: Download counter.txt, change the number to 0, upload
  2. Via SSH:
    echo "0" > counter.txt

To set a specific starting value:

echo "1000" > counter.txt
Caution: The file should only contain a number with no extra spaces or newlines.

Q4: Can I have multiple counters?

Yes! There are two methods for multiple counters:

Method 1: Separate Scripts

Copy the script for each page:

textcounter_home.pl  -> home_count.txt
textcounter_about.pl -> about_count.txt
Method 2: Query String Parameter

Use one script with a page parameter:

<!--#exec cgi="/cgi-bin/textcounter.pl?page=home"-->
<!--#exec cgi="/cgi-bin/textcounter.pl?page=about"-->

The script then creates separate count files for each page.

Q5: How do I format the counter display?

Customize the display by modifying these variables:

# Add leading zeros
$min_digits = 6;  # 000123

# Add commas
$use_commas = 1;  # 1,234,567

# Custom text
$prefix = "Visitors: ";
$suffix = " since Jan 2024";

Example outputs:

  • Default: 12345
  • With zeros: 012345
  • With commas: 12,345
  • With text: Visitors: 12,345 since Jan 2024

Q6: How do I prevent counting my own visits?

To exclude your own visits, add your IP to the ignore list:

@ignore_ips = (
    "123.45.67.89",       # Your home IP
    "98.76.54.32",        # Your work IP
    "192.168."            # Local network prefix
);

You can also use:

  • Partial IPs: "123.45." matches all in that range
  • Cookie-based exclusion: Set a cookie and check for it
  • Session timeout: Don't count repeat visits within X minutes
Tip: Find your IP at whatismyip.com and add it to the list.
Back to FAQ