Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Perl Cookies

Reply
Thread Tools

Perl Cookies

 
 
superman183@nowhere.com
Guest
Posts: n/a
 
      09-01-2005
Hi:

I'm trying, with zero success, to set multiple values in a single
cookies ... which I know shouldn't be that difficult at all. However,
whatever I try, it still seems to store only the first value. I'm using
a freebie piece of code from Bewley.net, which is in common usage, and
works fine, except for the fact I don't seem able to store multiple
values:

Here's the piece of code that does the cookie writing:

print "Set-Cookie: ";
print ($name1, "=", $value1, "; expires=", $expiration, "; path=",
$path, "; domain=", $domain, "; ", $secure, "\n");

print "Content-type: text/html\n\n";

However, if I try inserting $name2/$value2, separated from the first
value with a semi-colon, it just doesn't store it ... I even tried just
using plain text values to test it (ie. n=testvalue), but still nothing
.... The first name/value is stored perfectly.

Any ideas appreciated ... I would like to use the same code, rather
than a module, simply because of lack of overhead, although I'm sure
there are a number of modules out there ... I'm really more interested
in why I can't get the code above to work with multiple values.

Thanks in advance!
Superman183 aka. Susan

 
Reply With Quote
 
 
 
 
Scott Bryce
Guest
Posts: n/a
 
      09-01-2005
wrote:

> I'm trying, with zero success, to set multiple values in a single
> cookies


Am I mistaken, or can a cookie only store one value? What happens when
you try to set multiple cookies?
 
Reply With Quote
 
 
 
 
Eric Schwartz
Guest
Posts: n/a
 
      09-01-2005
"" <> writes:
> Here's the piece of code that does the cookie writing:
>
> print "Set-Cookie: ";
> print ($name1, "=", $value1, "; expires=", $expiration, "; path=",
> $path, "; domain=", $domain, "; ", $secure, "\n");
>
> print "Content-type: text/html\n\n";


Ick.

#!/usr/bin/perl
use warnings;
use strict;
use CGI qw/:standard/;
use CGI::Cookie;

my $cookie = new CGI::Cookie(-name => $name1,
-value => $value1,
-expires => $expiration,
-path => $path,
-domain => $domain,
-secure => $secure);
print header(-cookie => $cookie);
__END__

> However, if I try inserting $name2/$value2, separated from the first
> value with a semi-colon, it just doesn't store it ... I even tried just
> using plain text values to test it (ie. n=testvalue), but still nothing
> ... The first name/value is stored perfectly.


Your problem here is not with Perl; it's with your misunderstanding
about how cookies work. There's nothing wrong with that, but learning
how to partition your problems properly will aid you in finding
answers to your questions about it. In this case, you might try
posting your question to comp.infosystems.www.authoring.cgi, as they
will have more people who know more about that sort of thing.

> Any ideas appreciated ... I would like to use the same code, rather
> than a module, simply because of lack of overhead,


Once you've decided to use Perl, you have already used enough overhead
that the additional use of a module is nearly irrelevant, and they
will save you from all sorts of problems you haven't even considered
yet, such as escaping special characters in your cookie's name or
value. It's really worth it.

> although I'm sure
> there are a number of modules out there ... I'm really more interested
> in why I can't get the code above to work with multiple values.


Cookies don't work that way, but that's not Perl's fault; you need to
learn more about how cookies operate.

-=Eric
 
Reply With Quote
 
superman183@nowhere.com
Guest
Posts: n/a
 
      09-01-2005
A single cookie can certainly store multiple values, but I may be going
about it the wrong way, but separating the values with a semi-colon, as
per the rest of the values seems pretty logical. The rest of the
values, (ie. path, expiration etc,) when I'm trying to set multiple
values, are set correctly.

I did try setting multiple cookies, but it's not really what I want to
do, and - for other reasons - screwed up ...

Thx,
Susan

 
Reply With Quote
 
superman183@nowhere.com
Guest
Posts: n/a
 
      09-01-2005
Eric,

The question explicitly said, for good reason, that I don't wish to use
modules. I don't expect you to understand all of my reasons for that,
but if you can only reply with a reponse which explicitly includes
modules, and laced with plenty of attitude to boot, then I suggest you
don't bother answering at all.

Ok, so "... cookies don't work that way ..." ... That's fine, but I
need to know, if that's the case, how they do work, so I can modify my
code to do what I need it to. If someone is able to assist with /
explain that, then that would be truly appreciated.

Thanks.
Susan

 
Reply With Quote
 
Eric Schwartz
Guest
Posts: n/a
 
      09-01-2005
"" <> writes:
> The question explicitly said, for good reason, that I don't wish to use
> modules. I don't expect you to understand all of my reasons for that,
> but if you can only reply with a reponse which explicitly includes
> modules, and laced with plenty of attitude to boot, then I suggest you
> don't bother answering at all.


I'm sorry, did I miss the part where you get to dictate what sort of
response I make? This is USENET, not superman183's personal free
support desk. In any event, I have yet to receive your cheque, so
until then, I'm responding on my own time, however I care to. You
claim to have good reasons not using modules, but I may not agree
they're good, and in any event, someone finding this discussion later
on via Google will have a choice of solutions available to them even
if you don't like my solution.

> Ok, so "... cookies don't work that way ..." ... That's fine, but I
> need to know, if that's the case, how they do work, so I can modify my
> code to do what I need it to. If someone is able to assist with /
> explain that, then that would be truly appreciated.


And my point was that *that* information is entirely irrelevant to
Perl, and in fact will be the same information regardless of what
language you choose to implement your solution in, so you're better
off asking in a newsgroup which is actually about such things, and not
in a newsgroup which isn't.

In summary, I commented on the Perl-related aspect of your problem,
which comment you are free to ignore as you like, and told you where
to find help on the non-Perl-related aspect of your problem. I really
don't see why you're getting so upset about this.

-=Eric
 
Reply With Quote
 
superman183@nowhere.com
Guest
Posts: n/a
 
      09-01-2005
Not upset in the slightest Eric, but if you were to use your time
actually answering questions accurately and helpfully, and ignoring
those questions to which you're unable to provide a useful response,
then I know from experience that this newsgroup would be well-served.

Don't get all upset now ... lol.

Susan

 
Reply With Quote
 
superman183@nowhere.com
Guest
Posts: n/a
 
      09-01-2005
Oh look ... Eric still hasn't been able to provide a useful or accurate
response ... Never mind, maybe he's gone off to play with his toys.

Best,
Susan.

 
Reply With Quote
 
Eric Schwartz
Guest
Posts: n/a
 
      09-01-2005
"" <> writes:
> Not upset in the slightest Eric, but if you were to use your time
> actually answering questions accurately


What information did I provide that was inaccurate?

> and helpfully,


I pointed out a different solution, which I personally prefer, to your
Perl problem. You're not obligated to use it, but I'm not writing
just for you, I'm writing to anyone who has a similar problem now or
in the future. I also told you where to find the information about
your problem that was not Perl-related. What, exactly, was not
helpful about that? (Hint: "You didn't write my code for me" is not a
valid answer.)

I would note, by the way, that if you used CGI::Cookie, you could have
used ';', or any other character, to separate the multiple values in
your cookie, and it would have escaped everything properly.

> and ignoring those questions to which you're unable to provide a
> useful response, then I know from experience that this newsgroup
> would be well-served.


I'm not only entirely able to provide a useful response, I did. That
you don't wish to use it does not in the slightest affect its
usefulness in general.

> Don't get all upset now ... lol.


Gosh, I was going to get upset, but then I saw the 'lol', so now
everything's all cheery and hunky-dory! Golly gee whillikers, that's
lucky!

-=Eric
 
Reply With Quote
 
Eric Schwartz
Guest
Posts: n/a
 
      09-01-2005
"" <> writes:
> Oh look ... Eric still hasn't been able to provide a useful or accurate
> response ... Never mind, maybe he's gone off to play with his toys.


Oh look ... Susan won't be getting nearly as many helpful responses in
the future.

*PLONK*

-=Eric
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Give Request.Cookies and Response.Cookies is there any reason to use another method to use cookies? _Who ASP .Net 7 09-18-2008 07:49 PM
What's the proper way of reading cookies? Request.Cookies("mycook") doesnt work user ASP .Net 3 03-31-2007 01:53 PM
Response.Cookies vs Request.Cookies Alex Nitulescu ASP .Net 1 02-03-2005 09:43 AM
Persistent Cookies vs. session cookies Andy Fish Java 3 11-06-2003 10:44 AM
Good Cookies bad Cookies? AK Computer Support 23 10-26-2003 05:20 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57