Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Cannot get cookie counter to increment

Posted on 2009-02-17
2
Medium Priority
?
671 Views
Last Modified: 2013-12-25
My assignment requires that I show how many times a user has visited the site by using a cookie to count in Perl.  Although cookies are very simple, for some reason, I can not get my cookie to count past 1.  I have compared my information to online sources and it all looks correct, but not matter what it doesn't work.  Please view my code below.  Thank you!
#retreive count cookie
$count = cookie('Count');
 
$count++; (there are two plus signs here but for some reason the preview isn't showing them)
 
#there is a name cookie created here as well
$C_count = cookie(-name => "Count",
                               -value => "$count",
                               -expires => "+6M");
 
print header(-cookie => $C_name, $C_count);

Open in new window

0
Comment
Question by:deeayrian
2 Comments
 
LVL 10

Accepted Solution

by:
oleber earned 2000 total points
ID: 23667063
try:

in the CGI.pm seems that you a parameter to many
#retreive count cookie
$count = cookie('Count');
 
$count++; (there are two plus signs here but for some reason the preview isn't showing them)
 
#there is a name cookie created here as well
$C_count = cookie(-name => "Count",
                               -value => "$count",
                               -expires => "+6M");
 
print header(-cookie => $C_count);

Open in new window

0
 

Author Comment

by:deeayrian
ID: 23667127
Ah ha!  Thank you so much!  I actually need that other cookie in there to be printed (it is a different part of the code) but because you pointed out that portion of the code, when I removed the name cookie, it worked.  Then I realized that I had the code wrong for sending more than one cookie to the browser.  To send more than one cookie to the browser, the code is:  
print header(-cookie => [$C_name, $C_count]);

Thank you!
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question