> A quickie:
>
> What commands can you use in PERL to set and retrieve cookies
> from a users' browser?


no commands per se, it's a matter of playing with the headers.
take a look at the other message i've just posted (Re: WC:>:
Complex CGI question (possibly javascript)), for some background
information on what the headers do and how they're arranged.

someone else will have to give you the exact syntax that's used,
because the reference i normally use for headers is buried at
the moment, and i'm winging it.   rather than give you
innacurate information, i'll just admit that i don't know the
details.

in general terms, though, you set a cookie from perl by
including it as a header when you generate the reply:


    $cookie = "this is a cookie.";

    print <<__done;
    Cookie:  $cookie
    Content-type:  text/html

    [ .. webpage .. ]
    __done


and then, to read the cookie, you find it in the list of
environment varaibles which were passed to the server by the
browser:

    $cookie = $ENV{'COOKIE'};


the setting and reading are, frankly, the easy part.   there are
also issues of access restriction, expiration, and field
structure which need to be addressed.   those are what i don't
know off the top of my head, and it's better to send you to a
reliable source for the information than to make you play "guess
where Mike is talking rot".


i know that Netscape's technical section has a white paper that
lays out all the details of how cookies are structured.   in
fact, i think it's the authoritative version, since they're the
ones who implemented cookies first.   the HTTP 1.1 RFC (2068 i
think, but don't quote me) will also have a rundown, if cookies
have been accepted as part of the base standard.   that's
something else i don't recall.   to be honest, i'm not even sure
the header and the environment variable are each named
'Cookie'.. though logical guesses tend to have a fairly decent
hit rate in web protocols.


what you should do is start by finding the actual name of the
header that sets the cookie.   then use that in the following
script:


    set_cookie.pl
    --------
    #!/usr/local/bin/perl

    $cookie = "**** THIS ONE, RIGHT HERE ****";

    print <<__done;
    Cookie:  "$cookie"
    Content-type:  text/html

    <!doctype html public "-//W3C//DTD HTML 3.2 Final//EN">
    <html>
    <head>
    <title>SAMPLE COOKIE PAGE</title>
    </head>

    <body>

    Theoretically, this should have just set a cookie.
    <p>
    To check, <a href="read_env.pl">click here</a>

    </body>
    </html>

    __done

    ---- EOF ----


which will call this one:


    read_env.pl
    --------
    #!/usr/local/bin/perl

    $m = '.' x 24;

    for $k (sort keys %ENV) {
        $l = 24 - length ($k);
        push @out, sprintf ("<li> %s %.*s %s\n", $k, $l, $m, $ENV{$k});
    }

    print <<__done;
    Content-type:  text/html

    <!doctype html public "-//W3C//DTD HTML 3.2 Final//EN">
    <html>
    <head>
    <title>ENVIRONMENT LISTING</title>
    </head>

    <body>

    The current environment variables are:
    <tt>
    <ol>
    @out
    </ol>
    </tt>
    Presumably, the cookie should be in there somewhere.

    </body>
    </html>

    __done

    ---- EOF ----


and with any luck, you'll be able to spot the environment
variable you need.







mike stone  <[EMAIL PROTECTED]>   'net geek..
been there, done that,  have network, will travel.



____________________________________________________________________
--------------------------------------------------------------------
 Join The NEW Web Consultants Association FORUMS and CHAT:
   Register Today at: http://just4u.com/forums/
Web Consultants Web Site : http://just4u.com/webconsultants
   Give the Gift of Life This Year...
     Just4U Stop Smoking Support forum - helping smokers for
      over three years-tell a friend: http://just4u.com/forums/
          To get 500 Banner Ads for FREE
    go to http://www.linkbuddies.com/start.go?id=111261
---------------------------------------------------------------------

Reply via email to