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:
Cookies?

 



srdjans
Deleted

Jan 1, 2001, 10:19 PM

Post #1 of 4 (321 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 POSSIBLE.....no 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!
Respectfully,

Srdjan



sleuth
Enthusiast / Moderator

Jan 2, 2001, 12:19 AM

Post #2 of 4 (318 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. sleuth@seeki.com

Sleuth



BigRich
Novice

Jan 2, 2001, 2:37 AM

Post #3 of 4 (317 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 CGI.pm if you're not familiar with it. If you need any help figuring the code out, my email is bigrich318@yahoo.com.



#!/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>",
$q->end_html;




srdjans
Deleted

Jan 2, 2001, 4:23 PM

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

Hi!

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!

Regards,
Srdjan


 
 


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

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