in reply to LWP form post example not working

Hmmm, yeah, this sounds like there's a miscommunication going on between your script and the server.

You mention that it uses sessions. Does that mean it's setting a cookie? Your script, as written, will not accept cookies (or rather, forgets them as soon as it receives them).

If I were a login page, on successful POST I might respond with a cookie-setting redirect, then the protected page would check for the cookie, and if it's missing, redirect to the login page. You'd then see exactly the behavior you see above.

You could check for that by installing something like LiveHTTPHeaders for Firefox, or something similar - anything that lets you view the HTTP requests and responses. Then disable cookies and try to log in.

To enable your script to accept cookies, see the cookie_jar method in LWP::UserAgent, or just do this:

# Instead of $ua = LWP::UserAgent->new(); $ua = LWP::UserAgent->new(cookie_jar => {});
Good luck! --Clinton

Replies are listed 'Best First'.
Re^2: LWP form post example not working
by perlchild (Acolyte) on Oct 14, 2008 at 14:46 UTC
    I have added the line you suggested and still no luck logging in to the site. Since my php code is using sessions it does set the Set-Cookie: header to a PHPSESSID but once the post is finished that cookie is no longer valid. I tried to do a get on the login page an put that cookie in a variable and then tried to set that header on the post but that did not work either since the new cookie was different. I printed them out as I got and set them to make sure of that.