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

Greetings,
I'm developing a perl CGI script which uses a cookie to keep track of whether a user has logged in.
The cookie only holds a random string, the sql db holds the users' info.

I prefer to test scripts as I'm writing them, by running them from the command-line (linux).
Is there any way to simulate a browser passing a cookie to the script, when I run it from the command line?

I'd prefer the solution to work by somehow passing the 'cookie data' to the script, rather than simply faking it by creating a hash at the start of the script, and reading that instead of CGI.pm's cookie function. As that would require further changes to the script after the initial testing.

I've done a quick PM search, and google'd it, and haven't found anything that appears relevant.
Any suggestions at all would be most welcome.

Replies are listed 'Best First'.
Re: Command line cookies
by Kanji (Parson) on Apr 04, 2002 at 21:53 UTC

    Setting the HTTP_COOKIE or COOKIE enviroment variables before running the script should do the trick...

    # (ba)sh HTTP_COOKIE="..."; export HTTP_COOKIE # (t)csh setenv HTTP_COOKIE "..." # DOS set HTTP_COOKIE="..."

        --k.


      Thank you both for your suggestions.
      I've just tested the HTTP_COOKIE environment variable solution, and it's *exactly* what I was hoping for.
      Many thanks!
Re: Command line cookies
by RMGir (Prior) on Apr 04, 2002 at 21:53 UTC
    I believe curl (the standalone program) can handle arbitrarily complex cookie scenarios.

    Since it will also simulate GETs and POSTs, it's a good debugging tool.

    You can also use the -H header option on GET from the (lwp?) package to send your cookie: header.
    --
    Mike

    Edit: Thanks to jeffa for the URL for curl.