in reply to SOLVED! PHP Sessions and Perl

my $cgi = new CGI::Lite; my $cookies = $cgi->parse_cookies;

That will happily parse any cookies in the request from the browser to your CGI script. You are not calling your CGI script from a browser so there won't be any cookies.

Inspect the responses to your $mech object to extract the cookies from there instead.

PS. Don't use indirect object notation. my $cgi = CGI::Lite->new; is preferred.


🦛

Replies are listed 'Best First'.
Re^2: PHP Sessions and Perl
by bajangerry (Sexton) on Mar 16, 2021 at 17:30 UTC

    Hi Hippo,

    When I print the content of my $mech I get the below only, nothing relating the session or cookies. Is this maybe because the login page calls a different page to authenticate and assign the session info?
    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Login</title> <link rel="stylesheet" href="https://use.fontawesome.c +om/releases/v5.7.1/css/all.css"> <link href="lib/style.css" rel="stylesheet" type="text/css"> </head> <body> <div class="login"> <h1>Login</h1> <form action="authenticate.php" name="login" m +ethod="post"> <label for="username"> <i class="fas fa-user"></i> </label> <input type="text" name="username" pla +ceholder="Username" id="username" required> <label for="password"> <i class="fas fa-lock"></i> </label> <input type="password" name="password" + placeholder="Password" id="password" required> <input type="submit" value="Login" nam +e="login"> </form> </div> <div class="login"> <h2>If you don't have an account, please click to <A HREF="reg +ister.html">register</A></h2> </div> </body> </html>
      When I print the content of my $mech I get the below only, nothing relating the session or cookies.

      Set cookies are not returned in the content. They are returned in the response headers.

      use strict; use warnings; use WWW::Mechanize; use Data::Dumper; my $mech = WWW::Mechanize->new; my $response = $mech->get ('http://your.url.here/'); print Dumper ($response->headers->{'set-cookie'});

      🦛

        Ahhhhh!!! I have seen the light!!!