Writing cookies a problem
[email protected] ("Mark Wheeler") Thu, 14 Nov 2002 07:12:32 -0800
| Newsgroups | perl.macperl.webcgi |
|---|---|
| Message-ID | <[email protected]> |
------=_NextPart_000_0007_01C28BAD.33812560
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi,
I am having a little problem with cookies. I have tried it two different =
ways and still with moderate success. The first way works PERFECTLY... =
on a Mac... with both IE an Netscape. But, the cookies do not seem to be =
written on a PC. I am baffled!
The second way worked even less. On both Mac and PC I think the first =
cookie was written, and then I got text output of the rest of the perl =
script to the browser window of the 2nd and 3rd cookies and Location =
change. Again, I am baffled!
Any help would be much appreciated. I am trying to save some variables =
for later use with various pages of the site. Enclosed are the snippets =
regarding the cookies. Thanks again for your help.
Mark Wheeler
HERE IS THE FIRST WAY:
..
..
..
$email =3D substr($stringtemp, $passwordends+2, =
$stringtemplength-$passwordends-2);
$clientpage =3D substr($userentry, $pagestart, $totallength-$pagestart);
$clientname =3D substr($userentry, $pagestart+3, $pipe-$pagestart-3);
&setCookie("pfpemail", $email, "", "/", "www.tonedeafstudios.com");
&setCookie("pfppage", $clientpage, "", "/", "www.tonedeafstudios.com");
&setCookie("pfpname", $clientname, "", "/", "www.tonedeafstudios.com");
print "Location: ../clients/$clientpage\n\n";
exit;
..
..
..
..
#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
# Set Cookie =3D
#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
sub setCookie {
local($cname, $cvalue, $expiration, $path, $cdomain) =3D @_;
print "Set-Cookie: ";
print ($cname, "=3D", $cvalue, "; expires=3D", $expiration, "; =
path=3D", $path, "; domain=3D", $cdomain, "\n");
}
HERE IS THE SECOND WAY:
..
..
..
$email =3D substr($stringtemp, $passwordends+2, =
$stringtemplength-$passwordends-2);
$clientpage =3D substr($userentry, $pagestart, $totallength-$pagestart);
$clientname =3D substr($userentry, $pagestart+3, $pipe-$pagestart-3);
&setCookie("pfpemail", $email, "", "/", "www.tonedeafstudios.com");
&setCookie("pfppage", $clientpage, "", "/", "www.tonedeafstudios.com");
&setCookie("pfpname", $clientname, "", "/", "www.tonedeafstudios.com");
print "Location: ../clients/$clientpage\n\n";
exit;
..
..
..
..
#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
# Set Cookie =3D
#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
sub setCookie {
local($cname, $cvalue, $expiration, $path, $cdomain) =3D @_;
use CGI;
my $query =3D new CGI;
my $cookie_out =3D $query->cookie(-name=3D>$cname,=20
-value=3D>$cvalue,=20
-expires=3D>$expiration,=20
-path=3D>$path,=20
-domain=3D>$cdomain;
print $query->header(-cookie=3D>$cookie_out);=20
}
------=_NextPart_000_0007_01C28BAD.33812560--