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: Beginner:
Cookie expiry dates

 



RayStreet
Deleted

Jan 16, 2000, 4:26 PM

Post #1 of 5 (1245 views)
Cookie expiry dates Can't Post

I create a cookie with the expiry date set by the code:-
$expdate = "Monday, 17-Jan-01 00:00:00 GMT";

How do I change this so that the cookie expires 2 days from the currnet system date?

Any ideas would be appreciated.


brian.hayes
User

Jan 16, 2000, 5:02 PM

Post #2 of 5 (1247 views)
Re: Cookie expiry dates [In reply to] Can't Post

This isn't exactly what your looking for but it will help.. I comented this one to try to explain what is going on. Just change it around to fit what you need. Sorry for not doing this for you. If no one reply's soon I will take a better look for you.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


## This will print out date in a readable format.
## print gdate('/','yy/mm/dd','xxxx');
sub gdate{
## Must have three values passed to sub gdate.
## &gdate('/','dd/mm/yy','xx') format.
## first is the spacer between day month year.
## Second is the layout of date.
## Third is display 2 or 4 value year in date.
## Any value under two digets will produce two
## year value. Default is four. I.E. 2000.
if (!defined($_[0]) or !defined($_[1]) or !defined($_[2])){
return "gdate('/','dd/mm/yy','0000') Missing vars..";
}
my $spacer = $_[0] ;
my $format = $_[1] ;
my $myyear = length($_[2]) ;

## Must have some sort of mm/dd/yy format layed out..
if ($format eq ''){
return "Error! gdate('/','dd/mm/yy','0000') format.";
exit(0);
}

## Made it this far lets set some vars from out local time.
my $now = localtime(time);

## Split the vars from local time to readable vars....
my($week, $month, $day, $time, $year) = split(/\ /,$now);

## Set vars to them selves.. This just prevents error log buildup..

$week = $week;
$day = $day;
$time = $time;
$year = $year;
$month = $month;

## If we only want a two char output for year. Default is 1999,2000,2001.
if ($myyear <= 2) {
$myyear = $year;
my ($a,$b,$c,$d) = split(//,$myyear);
$year = "$c$d";
}
## Setup loop here with value=value, statments for text to number.
my @rm = ("Jan=1", "Feb=2", "Mar=3", "Apr=4", "May=4", "Jun=6",
"Jul=7", "Aug=8", "Sep=9", "Oct=10", "Nov=11", "Dec=12");
my $rm = "";

## Go through all months and replace text value to numeric values..
foreach $rm (@rm) {
## Slow down a little just incase we are getting hit hard.
#sleep(1);
## Split each value=value into $k and $v. $k is left side
## and $v is right
## side of $rm's value.
my ($k , $v) = split(/=/, $rm);
## Now match current system month to a numeric value from $rm.
if($k eq $month) {
## replace text with number value..
$month = $v;
## Determin layout, print and return to caller.
if ($format eq 'mm/dd/yy'){
return "$month$spacer$day$spacer$year";
}
if ($format eq 'mm/yy/dd'){
return "$month$spacer$year$spacer$day";
}
if ($format eq 'dd/mm/yy'){
return "$day$spacer$month$spacer$year";
}
if ($format eq 'dd/yy/mm'){
return "$day$spacer$year$spacer$month";
}
if ($format eq 'yy/dd/mm'){
return "$year$spacer$day$spacer$month";
}
if ($format eq 'yy/mm/dd'){
return "$year$spacer$month$spacer$day";
}

} ## End if for $k eq $month...
} ## End looping based on values in @rm.

## If you make it this fare without returning then give default UNIX style format.
## and return that value.
return $now;
} ## End sub.
</pre><HR></BLOCKQUOTE>

Brian Hayes

[This message has been edited by Borderline (edited 01-16-2000).]


japhy
Enthusiast

Jan 16, 2000, 5:14 PM

Post #3 of 5 (1245 views)
Re: Cookie expiry dates [In reply to] Can't Post

I suggest the use of the CGI::Cookie module, which allows you do to nifty things like

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


use CGI::Cookie;

$cookie = new CGI::Cookie;
$cookie->expires('+2d'); # automatically converts to two days from now
</pre><HR></BLOCKQUOTE>


Borderline
Deleted

Jan 16, 2000, 6:45 PM

Post #4 of 5 (1245 views)
Re: Cookie expiry dates [In reply to] Can't Post

Also if you happen to be using CGI.pm it allows for the same thing.
Cookie expires in 3 hours<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


use CGI;
$q = new CGI;
$cookie = $q->cookie(-name=>'mycookie',
-value=>'some info',
-expires=>'+3h');
print $q->header(-cookie=>$cookie);
</pre><HR></BLOCKQUOTE>
Cookie expires in 2 days<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


use CGI;
$q = new CGI;
$cookie = $q->cookie(-name=>'mycookie',
-value=>'some info',
-expires=>'+2d');
print $q->header(-cookie=>$cookie);
</pre><HR></BLOCKQUOTE>
2 Cookies expire in 1 year<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


$q = new CGI;
$cookie1 = $q->cookie(-name=>'mycookie',
-value=>'some info',
-expires=>'+1y');
$cookie2 = $q->cookie(-name=>'anouther cookie',
-value=>'some more info',
-expires=>'+1y');
print $q->header(-cookie=>[$cookie1,$cookie2]);
</pre><HR></BLOCKQUOTE>

Scott

[This message has been edited by Borderline (edited 01-16-2000).]


RayStreet
Deleted

Jan 16, 2000, 10:09 PM

Post #5 of 5 (1245 views)
Re: Cookie expiry dates [In reply to] Can't Post

Thanks for your help - I'm on to it.

Ray

 
 


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

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