Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I was working in a PHP site which use PHP session management to restrict access to some pages, well now i was playing with LWP::UserAgent and i was trying to make a POST into a form which is secure by the PHP session, but when i try to do it, i always get the error page ( which i made :} ), that happens cuz perl doesn't keep the session ( i think the browser is responsable for that ) Well then my question is, is some PERL way do that?? I hope i explain my problem well :}

Replies are listed 'Best First'.
Re: Php sessions and LWP
by dws (Chancellor) on Jun 11, 2003 at 04:05 UTC
    that happens cuz perl doesn't keep the session ( i think the browser is responsable for that )

    Assuming that "keep the session" means hanging on to a session cookie, you have at least two good options: The first is to hang on to the cookie yourself (see this snippet for code you can borrow) or you can use WWW::Mechanize to do the dirty work for you. I used to do the former, and now recommend the latter.

Re: Php sessions and LWP
by antirice (Priest) on Jun 11, 2003 at 04:07 UTC

    Since PHP4 sessions rely upon cookies (unless you set it to automatically add a session id token to all URLs it generates), you need to have your UserAgent keep track of the cookie that the php code sends to it and looks for every access during said session. Try using a cookie jar.

    use LWP::UserAgent; use HTTP::Cookies; use HTTP::Request; use strict; ... my $userAgent = LWP::UserAgent->new; my $cookie_jar = HTTP::Cookies->new; $cookie_jar->clear; $userAgent->cookie_jar($cookie_jar); ...

    Hope this helps.

    antirice    
    The first rule of Perl club is - use Perl
    The
    ith rule of Perl club is - follow rule i - 1 for i > 1