Hi, i'm trying to log in a phpbb forum with Perl using LWP::UserAgent. Here's what i tried :
#!"C:\perl\bin\perl.exe" use strict; use warnings; use HTTP::Cookies; use LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->cookie_jar(HTTP::Cookies->new(file => "cookie2.txt",autosave => 1 +,)); my $url_base = "http://www.host.com/login.php"; my $response = $ua->get($url_base); my $contenu = $response->content; $content =~ s/\n//g;#extracting session id my @sids = split(/sid=/,$content); my $id; shift(@sids); foreach $id(@sids){ $id =~ s!"(.*)!!; } my $res = $ua->post ($url_base.'?sid='.$sids[0],[username => 'myUserNa +me', password=>'myPassword',login=>'Connexion']);
i also tried WWW::Mechanize. Every time i launch my script, the host login page answers "bad login or password" (i checked the l/p i sent, they do work when sent via Firefox.) i captured the http headers of a succesful login connection made via firefox to understand:
http://www.host.com/login.php?sid=bfa659dd671fec73949f2f711a6c72d6 POST /login.php?sid=bfa659dd671fec73949f2f711a6c72d6 HTTP/1.1 Host: www.host.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1.13) +Gecko/20080311 Firefox/2.0.0.13 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9 +,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: http://www.host.com/index.php Cookie: eb033c292a139b620ecb662dda3f1a1b=-; mosvisitor=1; phpbb2mysql_ +data=a%3A2%3A%7Bs%3A11%3A%22autologinid%22%3Bs%3A0%3A%22%22%3Bs%3A6%3 +A%22userid%22%3Bi%3A-1%3B%7D; phpbb2mysql_sid=bfa659dd671fec73949f2f7 +11a6c72d6 Content-Type: application/x-www-form-urlencoded Content-Length: 49 username=myUserName&password=myPassword&login=Connexion HTTP/1.x 302 OK Date: Thu, 03 Apr 2008 07:16:46 GMT Server: Apache/1.3.34 Ben-SSL/1.55 X-Powered-By: PHP/4.4.8 Set-Cookie: phpbb2mysql_data=a%3A2%3A%7Bs%3A11%3A%22autologinid%22%3Bs +%3A0%3A%22%22%3Bs%3A6%3A%22userid%22%3Bs%3A3%3A%22190%22%3B%7D; expir +es=Fri, 03 Apr 2009 07:16:47 GMT; path=/ Set-Cookie: phpbb2mysql_sid=bfa659dd671fec73949f2f711a6c72d6; path=/ Location: http://www.host.com/index.php?sid=bfa659dd671fec73949f2f711a +6c72d6 Keep-Alive: timeout=2, max=200 Connection: Keep-Alive Transfer-Encoding: chunked Content-Type: text/html
i seem to post the good params at the good place. i don't see where i'm wrong :/

In reply to LWP::UserAgent can't login to phpbb forum by mnem0

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.