We help IT Professionals succeed at work.

Cannot get cookie counter to increment

deeayrian
deeayrian asked
on
Medium Priority
679 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

Comment
Watch Question

Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
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!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.