Hello everyone,
I'm having trouble getting this script working.
Current issue:
When running the script, I get "You have visited this page 1 time(s)." then when I refresh the page it continue showing "1" instead of incrementing up to "2".
Desired output:
When Launching the script a cookie is created and the counter start at 1. When the page is refreshed or visited again, the number increment up to 2, 3 and so on.
Can someone please help me out with this? Let me know if you need more info...
Here's my script:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
use CGI qwstandard -debug);
use strict;
use CGI::Carp qw(fatalsToBrowser);
use warnings;
#declare variables
my ($C_visits, $counter, %counter);
#Read the cookie to a variable
%counter = (cookie('$counter'))? cookie('$counter'):'none';
#create cookie
$C_visits = cookie(-name => "MyCookie",
-value => "$counter",
-expires => "+3M");
if (exists $counter{$_}) {
$counter{$_}++;
} else {
$counter{$_} = 1;
}
#send cookie to browser
# print header(-cookie => $counter);
#create Web page
print "<HTML>\n";
print "<HEAD><TITLE>My Counter</TITLE></HEAD>\n";
print "<BODY>\n";
print "<H1 ALIGN=left>Counter<BR></H1><HR>\n";
print "<ALIGN=left>You have visited this page $counter{$_} time\(s\).\n";
print "</BODY></HTML>\n";
I'm having trouble getting this script working.
Current issue:
When running the script, I get "You have visited this page 1 time(s)." then when I refresh the page it continue showing "1" instead of incrementing up to "2".
Desired output:
When Launching the script a cookie is created and the counter start at 1. When the page is refreshed or visited again, the number increment up to 2, 3 and so on.
Can someone please help me out with this? Let me know if you need more info...
Here's my script:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
use CGI qwstandard -debug);
use strict;
use CGI::Carp qw(fatalsToBrowser);
use warnings;
#declare variables
my ($C_visits, $counter, %counter);
#Read the cookie to a variable
%counter = (cookie('$counter'))? cookie('$counter'):'none';
#create cookie
$C_visits = cookie(-name => "MyCookie",
-value => "$counter",
-expires => "+3M");
if (exists $counter{$_}) {
$counter{$_}++;
} else {
$counter{$_} = 1;
}
#send cookie to browser
# print header(-cookie => $counter);
#create Web page
print "<HTML>\n";
print "<HEAD><TITLE>My Counter</TITLE></HEAD>\n";
print "<BODY>\n";
print "<H1 ALIGN=left>Counter<BR></H1><HR>\n";
print "<ALIGN=left>You have visited this page $counter{$_} time\(s\).\n";
print "</BODY></HTML>\n";