Cookie refresh questions....

H

hankology

Cookie refresh questions....
This is what I am currently doing:

# Step 1 - Read and save data from cookie
$XStrX = cookie('X_name');

# Step 2 - Create refreshed cookie with same data
$X_cookie_name = cookie(-name=>'X_name',
-value=>$XStrX,
-expires=>"+2h");

# Step 3 - Write refreshed cookie
print $q->header(-cookie=>$X_cookie_name);

However, the result is that the cookie data prints out on top of the
browser page instead of writing the cookie to the cookie file:

Set-Cookie: CI_name=07TW; path=/; expires=Tue, 03-May-2005 16:42:20 GMT
Date: Tue, 03 May 2005 14:42:20 GMT Content-Type: text/html;
charset=ISO-8859-1

So, if I may, I have three questions:
Why is the above code writing to the browser?
Am I over complicating a cookie refresh, and there is an easier way?
How do I make the cookie go away if the browser is closed?
Thanks!
 
B

Brian Wakem

Cookie refresh questions....
This is what I am currently doing:

# Step 1 - Read and save data from cookie
$XStrX = cookie('X_name');

# Step 2 - Create refreshed cookie with same data
$X_cookie_name = cookie(-name=>'X_name',
-value=>$XStrX,
-expires=>"+2h");

# Step 3 - Write refreshed cookie
print $q->header(-cookie=>$X_cookie_name);

However, the result is that the cookie data prints out on top of the
browser page instead of writing the cookie to the cookie file:

Set-Cookie: CI_name=07TW; path=/; expires=Tue, 03-May-2005 16:42:20 GMT
Date: Tue, 03 May 2005 14:42:20 GMT Content-Type: text/html;
charset=ISO-8859-1

So, if I may, I have three questions:
Why is the above code writing to the browser?


You must be printing a content-type header before. You can only print
one header.

Am I over complicating a cookie refresh, and there is an easier way?

Pass.


How do I make the cookie go away if the browser is closed?
Thanks!


You can only do this if the cookie is a session cookie - that is a
cookie which has no expiration time specified.


There's not much Perl in those questions.
 
H

hankology

Since I was doing it in perl, I thought it was appropriate. I did find
my problem was that I wrote the header previously. I did not know I
could not write a cookie half way through my session. I wonder how I do
it if I have to write the cookie after a form has been filled out and
the header has already been written??
Thank you.
 
J

J. Gleixner

Since I was doing it in perl, I thought it was appropriate. I did find
my problem was that I wrote the header previously. I did not know I
could not write a cookie half way through my session. I wonder how I do
it if I have to write the cookie after a form has been filled out and
the header has already been written??
Thank you.

You don't. You could process the information from the form, then send
the header, which includes the cookie, then your HTML.

This doesn't have anything to do with perl. There are many Web sites
that cover the use of cookies and session management, and quite a few
that discuss how to do it in perl.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,270
Latest member
TopCryptoTwitterChannels_

Latest Threads

Top