What’re the reasons that the server doesn’t actually recognize the cookie I set using WWW::Mechanize in the code below?
#!/usr/bin/perl
use strict;
use warnings;
use HTTP::Cookies;
use WWW::Mechanize;
my $cookie_jar = HTTP::Cookies->new(
file => "$ENV{'HOME'}/lwp_cookies.dat",
autosave => 1,
ignore_discard => 1
);
my $mech = WWW::Mechanize->new(
agent => 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13',
cookie_jar => $cookie_jar
);
$mech->get("http://somesite.ru");
$cookie_jar->set_cookie(1, "__cookie", '1', "/", ".somesite.ru");
#the following line prints the cookie's data
print $cookie_jar->as_string, "\n";
$mech->post("http://somesite.ru/action.php",
['foo' => 'bar']);
As you can see the server runs php. If I put in that action.php script:
var_dump($_COOKIE);
I’ll get an empty array anyway…
Thank you for all suggestions.
Try this (period before domain name removed):
Cookies for
.example.comare sent to the server if you accesswww.example.com,somehost.example.comand so on, but not sent if you accessexample.com. This is because.example.comdoes not matchexample.com.