[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Cookies, and again, cookies!



On Fri, May 26, 2000 at 02:17:24AM +0000, Sveinbjorn Thordarson wrote:
> Hi there,
> 
> I've been trying to use cookies with Perl, but CGI.pm has proved to be
> extremely frustrating.  I have an html form that sends a single value,
> 'login', to the script.  The script is then supposed to create cookie
> from the single login value, retrieve the cookie and print it in the
> browser.  I've read all the examples, sample scripts, manuals etc, but I
> cannot understand why this doesn't work.
> 
> #!/usr/local/bin/perl
> use CGI;
> $query = new CGI;
> 
> $login_value = $query->param('login');                #get from form
> 
> $cookie = $query->cookie(-name=>'login',              #Create cookie
>                          -value=>"$login_value",
>                          -expires=>'+1h',
>                          -path=>'/cgi-bin/',
>                          -domain=>'.soth.zoneit.com');
> 
> print $query->header(-cookie=>$cookie);               $get cookie
> 
> $login_from_cookie = $query->cookie(-name=>'login');
> 
> print "Content-type:text/html";
> print "<HTML><BODY>$login_from_cookie</BODY></HTML>";
> 
> Now, I'm getting extremely frustrated about all this.  I'm using
> Netscape 4.5, and I even tried it with IE (shudder!) but this doesn't
> work...period.  Could anyone enlighten me?  In any case, I'd really
> appreciate if someone could post some cookie code that works!

You're trying to set and get the cookie in a single request.  You have to
set the cookie in one request, and retrieve it in later requests.

Have an if statement which requests the cookie.  If it's set, print the
login information; if it's not, set the cookie, and print a link to query
the script again.

Ronald

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org