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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:



Jan 1, 2001, 10:19 PM

Post #1 of 4 (412 views)
Cookies? Can't Post

Hello everyone!

I was writing an application but I got stuck with the cookies. I saw a few libraries that handle cookies, and they were HUGE (I tried to modify them.....unsucessfully), and all I need are two subroutines AS SIMPLE AS fancy stuff.

I am in urgent need for two subroutines:

1. set cookie to expire on 01-01-3000, set the value in the cookie to the value generated by time() function, and set it only for the subdirectory (eg. dir name is TEST)
2. retrieve the cookie #1 and retrieve the value of time() stored in it, and RESET the value to the new value of time()

I would really appreciate help with this! Thank you in advance!


Enthusiast / Moderator

Jan 2, 2001, 12:19 AM

Post #2 of 4 (409 views)
Re: Cookies? [In reply to] Can't Post

 I tried to attach the file but it's too big. I found a file "cookie.lib" when I was in search of the same thing and it's been the easiest way to set cookies I've found yet. I highly recommend it, all you have to do is use the easy subs.

&SetCookies('name', 'Sleuth');

It's all in the file, I'll check if your email is available, if not mail me.



Jan 2, 2001, 2:37 AM

Post #3 of 4 (408 views)
Re: Cookies? [In reply to] Can't Post

No need for 2 subroutines. The code below will read the cookie value and place it in the variable $old_cookie_value ($old_cookie_value will be undefined or null if no cookie is present). It then sets a new/updated cookie with the current value in time(). The expiration is set to 10 years, you can't set it to 1000. If your script is not in the directory (or a sub) specified in path, it wont be able to access the cookie it's setting.

Read the docs for if you're not familiar with it. If you need any help figuring the code out, my email is

#!/usr/bin/perl -wT

use strict;
use CGI qw(:standard);
my $q = new CGI;
my $old_cookie_value = $q->cookie('visit_id_number');
my $new_value = time();
my $new_cookie = $q->cookie(-name=>'visit_id_number', -value=>$new_value, -expires=>'+10y', -path=>'/cgi-bin/test', -secure=>0);
print $q->header(-cookie=>$new_cookie);

# Test it. Click reload to update the cookie
print $q->start_html('Cookie Test'),
"<b>The old cookie value was: $old_cookie_value <p>
The new cookie value is: $new_value <p>
The entire new cookie is: $new_cookie</b>",


Jan 2, 2001, 4:23 PM

Post #4 of 4 (398 views)
Re: Cookies? [In reply to] Can't Post


Thanks for the answers!
I tried the code posted by BigRich and it works perfectly!

I have seen the cookie.lib (if you are referring to Matt Wright's cookie library) and it's awesome, but it is too big for my needs. I just needed something as simple as possible, and I got it :)

Thank you both for replying and helping out!



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

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