http://www.perlmonks.org?node_id=723549


in reply to Re: Stay logged in between requests with WWW::Mechanize
in thread Stay logged in between requests with WWW::Mechanize

Assuming the remote server is using cookies rather than session IDs (you can find out by closing your browser and then trying to reconnect without logging in: if you can, then it's cookies; otherwise, it's sessions)

I am confused. This doesn't make sense to me.

The site is using cookies, I'm certain. It's not passing session vars around. But closing and restarting the browser would only prove whether there were cookies which expired at some later date, instead of at the end of the session. Those are the "remember me" type cookies.

And, as I know that the site is sending cookies to my browser, why is Mech not getting those cookies and writing them to the cookies file? It knows where the file is and can write to it. But it doesn't write any cookies.



Nobody says perl looks like line-noise any more
kids today don't know what line-noise IS ...

Replies are listed 'Best First'.
Re^3: Stay logged in between requests with WWW::Mechanize
by sasdrtx (Friar) on Nov 14, 2008 at 03:48 UTC

    I'm not an expert at this, but why would a browser, or WWW:Mechanize write a session cookie to a file? It's only supposed to be around as long as the browser is running, so keeping it in memory only makes sense.


    sas
      That's logical, but I want it to DWIW!

      I guess the logical thing is that I would keep my script running in an endless loop, i.e. instead of a cron job running every five minutes, I run my script with while(1) and a five-minute sleep()?

      I don't love that idea.



      Nobody says perl looks like line-noise any more
      kids today don't know what line-noise IS ...
        I don't love that idea.

        Have you tried what the Anonymous Monk suggested?  from HTTP::Cookies:

        ignore_discard: save even cookies that are requested to be discar +ded (bool)

        Sounds like made for exactly that purpose...