[Bioperl-l] Cookie problems

Tariq Shafi tariq_shafi75 at hotmail.com
Sat Jul 17 14:01:53 EDT 2004


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



More information about the Bioperl-l mailing list