use warnings; use strict; use Digest::SHA1 qw( sha1_hex ); use WWW::Mechanize; use HTTP::Cookies; use LWP::Debug qw(+); login($ARGV[0], $ARGV[1]); sub login { my ($user, $pass) = @_; my $kennung = sha1_hex("$user + $pass"); my $cookie_jar = HTTP::Cookies->new( file => "/cookies/$kennung.dat", autosave => 1, ); my $mech = WWW::Mechanize->new( cookie_jar => $cookie_jar ); my $resp = $mech->get( 'http://www.perlmonks.org?node_id=109' ); die "HTTP-Error 1\n" unless $resp->is_success; $resp = $mech->submit_form( form_name => 'login', fields => { user => $user, passwd => $pass, } ); die "HTTP-Error 2\n" unless $resp->is_success; if ( $resp->content =~ // ) { print "log in ok"; } else { print "could not log in"; } } #### C:\devel>pmlogin.pl holli xxxxxxx LWP::UserAgent::new: () LWP::UserAgent::request: () HTTP::Cookies::add_cookie_header: Checking www.perlmonks.org for cookies HTTP::Cookies::add_cookie_header: Checking .perlmonks.org for cookies HTTP::Cookies::add_cookie_header: Checking perlmonks.org for cookies HTTP::Cookies::add_cookie_header: Checking .org for cookies LWP::UserAgent::send_request: GET http://www.perlmonks.org?node_id=109 LWP::UserAgent::_need_proxy: Not proxied LWP::Protocol::http::request: () LWP::Protocol::collect: read 847 bytes LWP::Protocol::collect: read 312 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 130 bytes LWP::UserAgent::request: Simple response: OK LWP::UserAgent::request: () HTTP::Cookies::add_cookie_header: Checking www.perlmonks.org for cookies HTTP::Cookies::add_cookie_header: Checking .perlmonks.org for cookies HTTP::Cookies::add_cookie_header: Checking perlmonks.org for cookies HTTP::Cookies::add_cookie_header: Checking .org for cookies LWP::UserAgent::send_request: POST http://www.perlmonks.org? LWP::UserAgent::_need_proxy: Not proxied LWP::Protocol::http::request: () LWP::Protocol::collect: read 847 bytes LWP::Protocol::collect: read 1648 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 1336 bytes LWP::Protocol::collect: read 310 bytes LWP::UserAgent::request: Simple response: OK could not log in