in reply to The Cookie Monster Returns......$ENV on tripod???????

can i not just create a cookie and then request its contents in the next line of the very same script?

Exactly.

The user agent (web browser) makes a request of the server. It has no cookie. It then waits for a response.

The web server receives the request and fills in all of the environmental variables. Since the user agent had no cookie when it made the request, $ENV{COOKIE} is not set. By the time your program gets control, CGI.pm attempts to pull a cookie out of $ENV{COOKIE}. The user agent still has no cookie. CGI.pm finds no cookie. Your program gets no cookie.

Your program then creates a cookie and sends information to the user agent.

The user agent will only send the cookie at its next request. You don't get an instantaneous reaction with this sort of programming. The client sends a chunk, then the server sends a chunk.

Make sense?

  • Comment on Re: The Cookie Monster Returns......$ENV on tripod???????

Replies are listed 'Best First'.
Re: Re: The Cookie Monster Returns......$ENV on tripod???????
by Anonymous Monk on Aug 28, 2001 at 05:49 UTC
    Thanx guys, Ive moved my account to prohosting now I tried my code there and the same thing is still happening i.e. cookie created by not able to read it back

    After I had created the cookie I edited my script so that it now only requested the cookie instead of creating it( the cookie is already there and it should therefore by sent to the script by the user agent) I searched for the cookie with

    my $cookie_in = $query->cookie("MY_NAME");

    but still nothing when I tried Andy's code I got the following....

    pkit_id=user_id&nirvana7&hash&965e21f712b38aa13586765230ccc75a
    pkit_session_id=c0fcc76283804096c4c56ca15e9eb4af

    THis is the code he used to retrieve his cookie
    my $rcvd_cookies = $ENV{'HTTP_COOKIE'}; my @cookies = split /;/, $rcvd_cookies; foreach my $cookie (@cookies) { print $cookie,"\n"; }
    Therefore the raw data of this return, has the two lines above seperated by a semicolon

    Im now initialising the cookie with....
    my $cookie_out = $query->cookie( -name=>"MY_NAME", -value=>"Barry Griffin", -expires=>'+24h', -path=>'/cgi-bin/~nirvana7', -domain=>'rain.prohosting.com', -secure=>0 );
    The cookie content is

    MY_NAME Barry%20Griffin rain.prohosting.com/cgi-bin/~nirvana7 0 1510090368 29437992 743584160 29437790 *

    MY Script is located at:
    http://rain.prohosting.com/~nirvana7/cgi-bin/dumb1.cgi