Page is a not externally linkable
- Code, Content, and Presentation
-- Perl Server Side CGI Scripting
---- Getting results from Javascript back to Perl


rocknbil - 4:28 pm on Dec 8, 2011 (gmt 0)


Why don't you just set and read the cookie in Perl?

At any rate, if the cookie is set, even in Javascript, it's set **in the browser.** It shouldn't matter, as long as it's on the same domain. On the next page* after the cookie is set, you should be able to do something like

# note that fred and Fred are not the same
my $cookievalue = &readCookie('Fred');
if ($cookievalue ne '') { print "cookie value is $cookievalue"; }
else { print "cookie not found, try reloading this page.*"; }


sub readCookie {
my ($cname,@cookiegroups,$grp,$cookkey,$cookval);
$cname = shift(@_);
if ($ENV{'HTTP_COOKIE'}) {
$ENV{'HTTP_COOKIE'} =~ s/\s+//g;
(@cookiegroups) = split(/;/,$ENV{'HTTP_COOKIE'});
foreach $grp (@cookiegroups) {
($cookkey,$cookval) = split (/=/,$grp);
if ($cookkey eq $cname){ return $cookval; }
}
}
return ''; # means no matching cookie found
}


* Note that, as Mr. Tabke says, you set a cookie and it can't be "read" until the browser sends it's value back to the server - usually on the next pageview.


Thread source:: http://www.webmasterworld.com/perl/4395572.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com