CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
counter modifications

 



parham_m_s
journeyman

Jun 13, 2000, 8:11 PM

Post #1 of 3 (1150 views)
counter modifications Can't Post

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


#!/usr/bin/perl

$url = 'http://www.com/web/scripts/count/digits';
$ext = 'gif';
$file = '/home/www/web/scripts/count/count.txt';

print "Content-type: text/html\n\n";
open(COUNT, $file); $count = <COUNT>; close(COUNT); ++$count;
@nums = split(//, $count);

foreach $num (@nums) {$display = "<img src=$url/$num.$ext>"; print $display; } # image
#foreach $num (@nums) {$display = "$num"; print $display; } # text

open(NCOUNT, ">$file");
print NCOUNT $count;
</pre><HR></BLOCKQUOTE>

i found this counter and i'm looking for somone to help me with modifications.

-i need reload protection; a file that will store ip's for 1 day (or a short period of time), then remove them.

-digit control. i want it so that i can specify the number of digits to be shown. for example, if i want 8 digits and my counter is currently at 123, it should show 00000123

-also, i'm not sure about structure, and i don't know if the coding is weak or not, i would appreciate help with that too.

thanks in advance for any help Smile.

[This message has been edited by parham_m_s (edited 06-13-2000).]


Kanji
User / Moderator

Jun 13, 2000, 9:00 PM

Post #2 of 3 (1150 views)
Re: counter modifications [In reply to] Can't Post

You probably want to use File::CounterFile instead as it has error checking and uses flock() to enforce serial updates.

The 0 padding issue is also a doddle with (s)printf.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

#!/usr/bin/perl -wT

use strict;
use File::CounterFile;

my $url = 'http://www.com/web/scripts/count/digits';
my $ext = 'gif';
my $file = '/home/www/web/scripts/count/count.txt';

printf q(<img src="%s/%08d.%s"> ),
$url,
File::CounterFile->new( $file, 0 )->inc,
$ext;</pre><HR></BLOCKQUOTE>

As for the 'reload protection', I'm not an advocate of using IPs as unique identifiers: it's becoming more and more common for people to be using a proxy of some sort, and while you only see 1 IP, there may be 10s, 100s, or 1000s of people sharing that same IP.

If you must use IPs, then the easiest, efficient way I can think of would be to write the IPs out to a directory as filenames and then use the -M file test operator to help identify which filenames/IPs to delete after a day.

That way, you could check if the IP exists as a file: if it does, do nothing; if it doesn't, increment the counter.


parham_m_s
journeyman

Jun 14, 2000, 3:44 AM

Post #3 of 3 (1150 views)
Re: counter modifications [In reply to] Can't Post

i'm not too good at perl... well i'm not good at perl at all. can someone help me with inserting the new code please Smile.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives