You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Alessandro Ambrosini <am...@hsgerardo.org> on 2000/09/15 23:35:34 UTC
Trouble setting multiple cookies
I'm novice to Embperl. Till now I've used PHP3 but I want to use Perl
(great !)
I know the feature of Embperl Session Management (using Apache::Session)
but I need to set multiple cookies in a single HTML page and I don't
want to use Session Management.
But settings multiple cookies doesn't work correctly.
My machine is a Pentium III with "clean and simple" installation of
Linux RedHat 6.2, Apache 1.3.12 , mod_perl 1.21 , Embperl 1.3b3 and
Netscape 4.72
Using PHP3 I've no problem: I can set many cookies without trouble. PHP3
function setcookie() works great !
I've set my Netscape preference to warn me when a cookie come in, so I
can see it.
1) My HTML code version 1
[-
$req_rec->header_out("Set-Cookie" => "name1=value1");
$req_rec->header_out("Set-Cookie" => "name2=value2");
$req_rec->header_out("Set-Cookie" => "name3=value3");
-]
<html>
<head>
<title>COOKIE TEST</title>
</head>
<body>
COOKIE TEST
</body>
</html>
With this ONLY THE FIRST cookie "name1" is seen from my netscape
The second "name2" and third "name3" disappear.
I've tried with $http_headers_out but it's the same.
Using :
$req_rec->header_out(
"Set-Cookie" => "name1=value1",
"Set-Cookie" => "name2=value2",
"Set-Cookie" => "name3=value3"
);
it' the same.
If $req_rec->header_out is an hash, I believe that this is correct:
"Set-Cookie" is the key and we can't have multiple value for the same
key, so only the first is seen.
How can I made it work ?
2) My HTML code version 2
<meta http-equiv="Set-Cookie" content="aaa=111">
<meta http-equiv="Set-Cookie" content="bbb=222">
<meta http-equiv="Set-Cookie" content="ccc=333">
<html>
<head>
<title>COOKIE TEST</title>
</head>
<body>
COOKIE TEST
</body>
</html>
With this all it's ok but happen a strange thing:
my netscape see "ccc" then "bbb" , then "aaa" (it's correct: cookie are
sent in reverse order) BUT again another "ccc".
The last cookie is always sent two times.
WHY ???
This is not a problem: cookies are saved correctly in browser (I see
only 3 cookies "aaa" "bbb" and "ccc"). "ccc" is overwritten.
With <meta http-equiv> I can set multiple cookies but I want understand
why the last cookie is sent 2 times.
3) EMBPERL_COOKIE_*
I've correctly set in my httpd.conf these vars using 'PerlSetEnv'.
They are in the %ENV of HTML page but ... they doesn't work when I send
a cookie.
As they don't exist.
This is an extract of my httpd.conf:
--------------<cut here>-----------
Alias /perl/ /home/httpd/perl/
AddType text/html .epl
PerlSetEnv EMBPERL_ALLOW \.epl$|\.htm$
PerlSetEnv EMBPERL_LOG /tmp/embperl.log
PerlSetEnv EMBPERL_DEBUG 1
PerlSetEnv EMBPERL_COOKIE_NAME cookiename
PerlSetEnv EMBPERL_COOKIE_DOMAIN dummy.org
PerlSetEnv EMBPERL_COOKIE_PATH /
PerlSetEnv EMBPERL_COOKIE_EXPIRES 980000000
<Files *.epl>
SetHandler perl-script
PerlHandler HTML::Embperl
Options +ExecCGI
</Files>
<Location /perl>
SetHandler perl-script
PerlHandler HTML::Embperl
Options +ExecCGI
</Location>
--------------<cut here>-----------
Where is the error ?
4) A very stupid question:
I want set a local var with the URL-encoded value of another var.
[- $escmode=2 -]
and then ???
I've tried various code but none work
In PHP there is a function urlencode() that do this, but in Embperl ?
Many thanks in advance
ambrosa@hsgerardo.org
Re: Trouble setting multiple cookies
Posted by Gerald Richter <ri...@ecos.de>.
>
> [-
> $req_rec->header_out("Set-Cookie" => "name1=value1");
> $req_rec->header_out("Set-Cookie" => "name2=value2");
> $req_rec->header_out("Set-Cookie" => "name3=value3");
> -]
>
header_out only set can set one http header with the same name. You have to
use the table API and the add method. See "perldoc Apache::Table"
>
> 3) EMBPERL_COOKIE_*
> I've correctly set in my httpd.conf these vars using 'PerlSetEnv'.
> They are in the %ENV of HTML page but ... they doesn't work when I send
> a cookie.
> As they don't exist.
>
This is only for %udat session handling, not for cookies you send.
If you want to use %udat you need also to set EMBPERL_SESSION_CLASSES, see
session handling in the Embperl docs.
>
>
> 4) A very stupid question:
>
> I want set a local var with the URL-encoded value of another var.
>
> [- $escmode=2 -]
>
This only has an effect on the output. There is no function provided by
Embperl at the moment to do so. Use some of the URI modules for that
purpose.
Gerald