For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > May 2004 > A cookie is not stored









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author A cookie is not stored
J. Alejandro Ceballos Z.

2004-05-22, 11:32 am

I am trying to make a cgi that set two cookies and return to the original page.

Almost everything works fine, but only the second cookie is stored, not the
first one. If I ask for their values before using header, they have the
correct values.

In the other hand, if you see, I am using a -location inside the header. I
don't know if it is correct, or how to redirect to a page if using redirect
with header gives me some problems (note commented line).

I will appreciate any clue (maybe a little mistake).


------

use CGI;
use MIME::Base64;

$cgi_this = new CGI;
$str_somedata = $cgi_this->param('password');
$value1 = encode_base64("some stuff : $str_somedata");
$value2 = encode_base64("more data");
$returnpage = $ENV{HTTP_REFERER};

$cook_admin = $cgi_this->cookie(-name=>'admin', -value=>$value1);
$cook_session = $cgi_this->cookie(-name=>'session', -value=>$value2);

# print $cgi_this->redirect(-uri=>$returnpage);
# print $cgi_this->header(-cookie =>[$cook_admin,$cook_session]);
print $cgi_this->header(-cookie =>[$cook_admin,$cook_session],
-location=>$returnpage);

--


Saludos,


J. Alejandro Ceballos Z. |
---------------------------+---------------------------
http://alejandro.ceballos.info |
buzon@alejandro.ceballos.info | "El pao siempre termina
-------------------------------+ por darnos alcance,
Tel: (33) 3647-7809 | por mucho que corramos."
Cel: (33) 1076-4705 |
| -- El enigma de Cambises, Paul S.


William McKee

2004-05-22, 11:32 am

Hi Alejandro,

The CGI.pm docs spell out how to use multiple cookies:

To create multiple cookies, give header() an array reference:

$cookie1 = $query->cookie(-name=>'riddle_name',
-value=>"The Sphynx's
Question");
$cookie2 = $query->cookie(-name=>'answers',
-value=>\%answers);
print $query->header(-cookie=>[$cookie1,$cookie2]);

HTH,
William

--
Knowmad Services Inc.
http://www.knowmad.com
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com