[rochester-pm-list] Cookies...

Brian Mathis bmathis at directedge.com
Mon Jan 3 15:22:43 CST 2000


On Mon, 3 Jan 2000, Fred Edmister wrote:
> 	I've got a script that makes a cookie... No problem... Only one thing I 
> need help with... How can I send something to it... (ie 
> myscript.pl?value=1234) and then use the $value 1234 in the script... 
> :)  Thanks in advance to anyone who may help!!
> 
> 	Fred

Here's how the web works:

----A standard page request:
    1. The browser sends a request to the server using the HTTP protocol.
This request is composed of just an HTTP header, the "GET" method.

    2. The server responds with 2 things:
	- An HTTP header
	- Data
       The HTTP header contains all sorts of info, including the MIME type
of the data, the date, time, last updated, etc.

    3. The browser displays the data, if it's HTML it will render it, if
it's some other type of data, it will invoke whatever helper application
that is registered for that mime type.


----Here's how a "form" transaction takes place.  We'll assume that the
user has already loaded the form, filled out the fields, and is ready to
hit submit.  Until the point where the user hits submit, it is no
different than a regular HTML page request.
    1. User presses the submit button
    2. The browser collects all the information that was in the form,
and packages it up into "form encoded" format.
    3. The browser sends a request to the server, using the HTTP
protocol.  This time, it uses the "POST" method.  The POST method includes
2 parts:
	- The HTTP header that says "this is a POST method"
	- the DATA from the form
    4. The server accepts the data, and sends it through the backend
program to process the data.
    5. The server responds with an HTTP response that contains:
	- the HTTP header
	- the DATA that is output from the program that processed the data



Where do cookies fit in?

----A page request that SETs a cookie:
    1. the browser requests a page using the HTTP GET method
    2. the server responds with:
	- the HTTP header.  The cookie is stored inside this HTTP header
	- the DATA, which is the HTML

----Each subsequent request to that web site:
    1. the browser requests a page using the HTTP GET method.  This time,
because there is a cookie for this site, the browser will include the
COOKIE when it sends the request
    2. The server responds using HTTP to the browser with
 	- HTTP header
	- HTML data

What does this mean?  When you set a cookie, that cookie gets sent with
EVERY subsequent request to that same web site.  There is no "cookie set
up" on the other end that you can now "talk to" somehow.  If you want to
change the value of the cookie, you just write over it by setting a new
cookie with the same name.

Use the CGI.pm methods for dealing with cookies.

-- 
Brian Mathis
Direct Edge
http://www.directedge.com




More information about the Rochester-pm mailing list