You need to add the cookie jar to the user agent:
$ua->cookie_jar(file => 'cookies.txt',
autosave => 1);
Do it at the beginning of the code, just after the creation of the user agent, not after the first request. You don't need to extract the cookies or anything - just add the cookie jar that's all. And you don't need the redirect_ok when you do the redirection manually.
I would correct your code if you cared to add code tags. |