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: Perl Programming Help: Intermediate:
Counters Needed

 



falazar
Deleted

Feb 1, 2000, 11:04 AM

Post #1 of 9 (3030 views)
Counters Needed Can't Post

Having massive troubles setting up all these wonderful "free" counter scripts... something is not working in most all of them and is very very frustrating cause the help for them is almost nonexistant....
I need a very simple counter... just an image or text that I can understand and modify later maybes..... and I dont have SSI as far as I know... at least it didnt work either...
thanx


Jasmine
Administrator

Feb 1, 2000, 3:42 PM

Post #2 of 9 (3030 views)
Re: Counters Needed [In reply to] Can't Post

What errors are you receiving when you install the counters? (Silly question, but) are you following the installation instructions? Have you checked to make sure that your web server is running the operating system and version of Perl that the counters require?

I'm not sure what you're asking here, but it's rather odd that you've tried several different counter scripts and none work.

(If you choose to reply to this message, we'll move it over to "I need a program that..." -- this isn't an intermediate programming question.)


falazar
Deleted

Feb 1, 2000, 4:25 PM

Post #3 of 9 (3030 views)
Re: Counters Needed [In reply to] Can't Post

Well lets see
What errors are you receiving when you install the counters?
none unfortunately... if i was getting an error I could maybe get some help or fix it :} I just get the no image thing on the html page

are you following the installation instructions?
yes....

Have you checked to make
sure that your web server is running the operating system and version of Perl
that the counters require?
what version they require? am running unix
on the school server here.. thats about al I know... Have written a couple other things guestbook and such by myself that work fine...

I'm not sure what you're asking here, but it's rather odd that you've tried several
different counter scripts and none work.
yes thats what I thought... Figured one of them might work.... but with all the stuff I have to change to make them work Im afraid that Ive just gotten some little something wrong and dont really know how to check it... :{


patk
Deleted

Feb 1, 2000, 8:28 PM

Post #4 of 9 (3030 views)
Re: Counters Needed [In reply to] Can't Post

Counters are actually very simple, and
there are others options to SSI.

Here is an example simple counter:
#!/usr/bin/perl

# Define database.
$data = "path/to/database.db";

# If the database doesn't exist, make it.
if (! $data) {
open(DATA,">$data");
print DATA "0";
close(DATA);

# If it's already made, add new count:
} else {
# Grab old count
open(FILE,"$data");
$count = <FILE>;
close(FILE);

# Add 1 to $count.
$count += 1;

# Save database with new count.
open(NEW,">$data");
print NEW "$count\n";
close(NEW);

# Return new count.
print "Content-type:text/html\n\n";
print "$count\n";
exit;

Save it as something.pl or something.cgi.

If you do not have SSI, you can also use
JavaScript.
IE:
<Script Language="JavaScript" src="counter.cgi">
<!--
//-->
</script>

----Hope that helps.
patk@self-made-man.com


falazar
Deleted

Feb 2, 2000, 5:57 PM

Post #5 of 9 (3030 views)
Re: Counters Needed [In reply to] Can't Post

Well tried that out.. the script works ok after i added the close bracket... }
but it still wont load from the webpage.. javscript wont load it... it is here....

omega.uta.edu/~jdr3317/count

how can i look and test it with SSI to make sure I DONT have it.... adn is their any other way to actually call it thru javascript or some other method


falazar
Deleted

Feb 3, 2000, 6:38 AM

Post #6 of 9 (3030 views)
Re: Counters Needed [In reply to] Can't Post

thank you very much... modified version works great :}

gives me a nice way around cgi and also a good way to mix all my javascript and cgi progs :}
my main webpage is here....
falazar.homepage.com
hopefully will have all the counters up soon :}


falazar
Deleted

Feb 3, 2000, 7:29 AM

Post #7 of 9 (3030 views)
Re: Counters Needed [In reply to] Can't Post

Here's my modified version mixed with another database... seems to work quite well.. :}


#!/usr/bin/perl
use CGI qw(:standard);

if (param())
{
# Define database.
$datafile = "data.db";
# Grab old count
open(FILE,"$datafile") or &dienice("Couldn't open file for reading.
Please notify webmaster Falazar.");

$page = param("page");

@data = <FILE>;
close(FILE);

print "Content-type:text/html\n\n";

# Save database with new count.
open(NEW,">$datafile");

foreach $i (@data)
{
chomp($i);
($ispage, $count) = split(/\|/,$i);

# print "document.write(\"$ispage $page $count\")\n";

if ($page eq $ispage)
{
$count += 1;
# Return new count.
print "document.write(\"$count\")\n";
$found = "true";
}
print NEW "$ispage|$count\n";
} # of for loop
if ($found eq "true") { }
else
{
print NEW "$page|1\n";
print "document.write(\"1\")\n";
}
close(NEW);


exit;
}
else # if no parameters
{
print "document.write(\"ERROR NO PAGE NAME\")\n";
}

sub dienice {
($msg) = @_;
print "<h2>Error</h2>\n";
print $msg;
exit;
}


patk
Deleted

Feb 3, 2000, 10:47 AM

Post #8 of 9 (3030 views)
Re: Counters Needed [In reply to] Can't Post

Well, you are trying
to return graphics! I have my own graphics counter that will return graphics:
#####################################
#!/usr/bin/perl

# The HTTP path to images:
$pathtoimages = "http://omega.uta.edu/~jdr3317/count/";
# The UNIX path to the counter.
$pathtocounter = "counter.ing";
# How many digits shall count.cgi show?
$number_of_digits = "01";
# What is the extension of the images?
$end = ".gif";
if (! $pathtocounter) {
open(DATA,">$pathtocounter");
print DATA "";
close(DATA);
}
print "Content-type: text/html\n\n";
open (COUNTER, "$pathtocounter");
$count = <COUNTER>;
chop ($count) if $count =~ /\n$/;
close (COUNTER);
$count += 1;
open (COUNTER, ">$pathtocounter");
print COUNTER ("$count");
close (COUNTER);
@digits = split(//, $count);
if ($number_of_digits eq "") {
$howmany = @digits;
} else {
$howmany = $number_of_digits;
}
$spline = '%0' . $howmany . 'd';
$count = sprintf("$spline", $count);
@digitimages = split(//, $count);
foreach $digitimage (@digitimages) {
$image = "<img src=$pathtoimages" . "$digitimage" . "$end>\n";
print ("$image");
}
exit;
################################
But you need graphics of up to 0 to 9 which there are millions at http://www.digitmania.holowww.com/ I revised the counter below that works with JavaScript, I forgot about the document.write("");
#######################################
#!/usr/bin/perl

# Define database.
$data = "path/to/database.db";
# If the database doesn't exist, make it.
if (! $data) {
open(DATA,">$data");
print DATA "0";
close(DATA);
# If it's already made, add new count:
} else {
# Grab old count
open(FILE,"$data");
$count = <FILE>;
close(FILE);
# Add 1 to $count.
$count += 1;
# Save database with new count.
open(NEW,">$data");
print NEW "$count\n";
close(NEW);
# Return new count.
print "Content-type:text/html\n\n";
print "document.write(\"$count\")\;\n";
exit;
}
<Script Language="JavaScript" src="counter.cgi">
<!--
//-->
</script>
#########################################
Ok, to call a script with SSI, try inserting this into a html file:

<!--#exec cgi="count.cgi"--> or
<!--#include virtual="count.cgi"--> oth of those are SSI.

I hope that helps.


patk
Deleted

Feb 3, 2000, 10:48 AM

Post #9 of 9 (3030 views)
Re: Counters Needed [In reply to] Can't Post

Well, you are trying
to return graphics! I have my own graphics counter that will return graphics:
#####################################
#!/usr/bin/perl

# The HTTP path to images:
$pathtoimages = "http://omega.uta.edu/~jdr3317/count/";
# The UNIX path to the counter.
$pathtocounter = "counter.ing";
# How many digits shall count.cgi show?
$number_of_digits = "01";
# What is the extension of the images?
$end = ".gif";
if (! $pathtocounter) {
open(DATA,">$pathtocounter");
print DATA "";
close(DATA);
}
print "Content-type: text/html\n\n";
open (COUNTER, "$pathtocounter");
$count = <COUNTER>;
chop ($count) if $count =~ /\n$/;
close (COUNTER);
$count += 1;
open (COUNTER, ">$pathtocounter");
print COUNTER ("$count");
close (COUNTER);
@digits = split(//, $count);
if ($number_of_digits eq "") {
$howmany = @digits;
} else {
$howmany = $number_of_digits;
}
$spline = '%0' . $howmany . 'd';
$count = sprintf("$spline", $count);
@digitimages = split(//, $count);
foreach $digitimage (@digitimages) {
$image = "<img src=$pathtoimages" . "$digitimage" . "$end>\n";
print ("$image");
}
exit;
################################
But you need graphics of up to 0 to 9 which there are millions at http://www.digitmania.holowww.com/ I revised the counter below that works with JavaScript, I forgot about the document.write("");
#######################################
#!/usr/bin/perl

# Define database.
$data = "path/to/database.db";
# If the database doesn't exist, make it.
if (! $data) {
open(DATA,">$data");
print DATA "0";
close(DATA);
# If it's already made, add new count:
} else {
# Grab old count
open(FILE,"$data");
$count = <FILE>;
close(FILE);
# Add 1 to $count.
$count += 1;
# Save database with new count.
open(NEW,">$data");
print NEW "$count\n";
close(NEW);
# Return new count.
print "Content-type:text/html\n\n";
print "document.write(\"$count\")\;\n";
exit;
}
<Script Language="JavaScript" src="counter.cgi">
<!--
//-->
</script>
#########################################
Ok, to call a script with SSI, try inserting this into a html file:

<!--#exec cgi="count.cgi"--> or
<!--#include virtual="count.cgi"--> both of those are SSI.

I hope that helps.

 
 


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

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