[Bioperl-l] Cookie problems

Lincoln Stein lstein at cshl.edu
Sat Jul 17 15:21:29 EDT 2004


Hi,

It looks like the cookie is being returned to the first script but not the 
second one.  Possibly your browser is confused.  Try clearing out the cookies 
in your browser and starting fresh.

lincoln


On Saturday 17 July 2004 02:01 pm, Tariq Shafi wrote:
> Hi
>
> I am having a lot of problem with cookies. I was using cookies and then I
> implemented a script to clear the contents of a cookie (a hash). Since
> then, my cookies have not been working. I have tried everything and have
> looked at the code dozens of times.
>
> Have any of you had an experience of this?
>
> Below is my code. Please let me know if you can help, greatly appreciated.
>
> Regards
>
> Tariq
>
> ----------------------------------------
>
> #!/usr/bin/perl
>
> use CGI qw(:standard);
>
> $query = new CGI;
> %hash = $query->cookie(-name=>"ns_id");
>
> #This array (@newerelements) takes all the selected checkboxes stored in
> the page submitting to the dynamic script.
> #The checkbox group is called ' '.
> #The checkboxes contain ID's, which are implemented as keys in a hash (to
> avoid duplicates and
> #allow ordering).
>
> @newelements = $query->param(' ');
>
> for ($i = 0; $i < scalar @newelements; $i++)
> {
> 	$hash{$newelements[$i]} = "";
> }
>
> #I'm updating (or trying to) update the cookie here and passing it into the
> dynamic script header.
>
> $ns_id = $query->cookie(-name=> "ns_id", -value=>\%hash, -domain=>(...),
> -path=>'/pad/cgi-bin/',
> -expires=>"+1y" );
>
> print $query->header(-type=>"text/html", -cookie=>$ns_id);
>
> if (defined $ns_id)
>
> {
> 	#Printing out the %hash keys, which come out as expected.
>
>                 print "Hash values: ";
> 	foreach $key (sort {$a<=>$b} keys %hash)
> 	{	print $key, br();
> 	}
>
>                 #The selected checkboxes (in @newelements) are the same as
> the %hash keys
>
> 	print "Newer elements:";
>
> 	for ($i = 0; $i < scalar @newelements; $i++)
> 	{	print "$newelements[$i]\n";
> 	}
>
> 	print br();
>
> }
>
> ------------------------------
>
> Then I have a script called 'Alignments.pl', which is supposed to take the
> ID's, ascertain information from them in a database and then do alignments
> using BioPerl. At this point nothing pertaining to the cookie value (the
> hash) is printed out.
>
> #!/usr/bin/perl
>
> use CGI qw(:standard);
> #require "./cgi-lib.pl";
> use DBI;
>
> $query = new CGI;
> %hash = $query->cookie(-name=>"ns_id");
>
> $dbh = DBI->connect(...)
>
> print $query->header(-cookie=>$ns_id);
>
> if ( defined $cookie) {
>
> print "Cookie Defined", br();
>
> #NOTHING IS PRINTED OUT HERE
> foreach $key(sort {$a<=>$b}keys %hash)
> {print $key, " ";
> }
>
> }
>
> -------------------------------
> Below is the script that was used to clear the cookie hash values
>
> #!/usr/bin/perl
>
> use CGI qw(:standard);
>
> $query = new CGI;
>
> %hash = $query->cookie(-name=>"ns_id");
>
> foreach $key (sort keys %hash)
> {delete $hash{$key};
> }
>
> $ns_id = $query->cookie(-name=> "ns_id", -value=>\%hash, -domain=>(...),
> -path=>'/pad/cgi-bin/',
> -expires=>"+1y" );
>
> print $query->header(-cookie=>$ns_id);
>
> _________________________________________________________________
> It's fast, it's easy and it's free. Get MSN Messenger today!
> http://www.msn.co.uk/messenger
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at portal.open-bio.org
> http://portal.open-bio.org/mailman/listinfo/bioperl-l

-- 
Lincoln Stein
lstein at cshl.edu
Cold Spring Harbor Laboratory
1 Bungtown Road
Cold Spring Harbor, NY 11724
(516) 367-8380 (voice)
(516) 367-8389 (fax)


More information about the Bioperl-l mailing list