Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: Stay logged in between requests with WWW::Mechanizeby oko1 (Deacon) |
on Nov 14, 2008 at 02:25 UTC ( [id://723543]=note: print w/replies, xml ) | Need Help?? |
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), you need to not only specify the cookie_jar that you're using but to also load it. I find that setting the cookie_jar and "autosave" in the call to 'new()' causes W::M to spit out errors - so I tend to do it manually. Sample script follows:
Assuming that you start with an empty "/tmp/cookies", this will populate it with a cookie the first time you run it (and show you a silly message that indicates that); subsequent runs will show that the cookie has been set and is active. Do note that the above PHP script has a fairly short cookie lifetime (2 minutes, if I recall correctly.)
-- "Language shapes the way we think, and determines what we can think about." -- B. L. Whorf
In Section
Seekers of Perl Wisdom
|
|