473,387 Members | 1,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Inserting cookies into a web session

I'm developing a web application that needs a semi-persistent way to
store information.

I've looked at some options such as writing entries to a database table
or creating small textfiles, but I'm not thrilled with anything I've come
up with so far.

Then a coworker suggested that I could just insert a cookie into the
current session, which would store whatever information I wanted. This
seems like a really good solution. That's what cookies are *for*, right?

But I've never worked with cookies before. Is there a Python package for
handling cookies? And are there any back-end requirements? I assume you
would have to be running a webserver that supports sessions. Do you also
have to be running some sort of web container or servlet engine?

Thanks for any suggestions.

--
John Gordon A is for Amy, who fell down the stairs
go****@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

Jul 23 '08 #1
2 1296
John Gordon wrote:
I'm developing a web application that needs a semi-persistent way to
store information.

I've looked at some options such as writing entries to a database table
or creating small textfiles, but I'm not thrilled with anything I've come
up with so far.
What's the problem?
Then a coworker suggested that I could just insert a cookie into the
current session, which would store whatever information I wanted. This
seems like a really good solution. That's what cookies are *for*, right?
Before using cookies keep in mind that the cookies returned by the
browser are not trustworthy! You have to validate the values each time.
But I've never worked with cookies before. Is there a Python package for
handling cookies?
http://docs.python.org/lib/module-Cookie.html
And are there any back-end requirements?
No.
I assume you
would have to be running a webserver that supports sessions.
You can do this all within your web application.
Do you also
have to be running some sort of web container or servlet engine?
No.

Ciao, Michael.
Jul 24 '08 #2
In <t8************@nb2.stroeder.com=?ISO-8859-1?Q?Michael_Str=F6der?= <mi*****@stroeder.comwrites:
John Gordon wrote:
I'm developing a web application that needs a semi-persistent way to
store information.

I've looked at some options such as writing entries to a database table
or creating small textfiles, but I'm not thrilled with anything I've come
up with so far.
What's the problem?
The problem is databases and textfiles are too heavyweight. I only need
the information for the duration of a session; I don't want to have to worry
about cleaning up the database or textfile afterwards.

To explain my requirements a bit more, I'm writing a web-based contact
manager application. The basic contact unit is a person, and I'm currently
working on the page layout for displaying information relating to a person.

The top section of the page is always the same: it shows your personal
information. Name, userid, title, etc.

But the bottom section of the page can change; it shows one of several
different kinds of information. It can either display your home and office
address, or it can show all the ways you can be contacted (phone, email,
pager, etc), or it can show the times during which you wish to be contacted.

(I didn't choose this layout; it was all done and approved before I joined
the project. I just have to implement it.)

My problem is if the user goes to the top portion of the page and changes
some of the information there, for example he wants to change his title,
that information is self-contained in a form and knows nothing about the
choice the user made of what to show at the bottom of the page.

Of course, I could add the choice as a hidden form element at the top of
the page. But that seems kludgy -- that form *shouldn't* have to know.
And the page layout isn't as simple as I've described here; there are
actually lots of these little self-contained forms that are unrelated to
the information at the bottom of the page, and I'd rather not have to
add a hidden element to all of them.

Using a cookie seems like an ideal solution. When the session starts,
I can set the choice to the default setting of "address", and if the user
ever clicks on "show me my contact methods" or "show me my times", I just
set the cookie to that choice. I don't have to worry about passing the
choice around in each of the dozen or so forms that are on the page.
Before using cookies keep in mind that the cookies returned by the
browser are not trustworthy! You have to validate the values each time.
I'm not sure it's worth the trouble in my case. I won't be depending on
the cookie for sensitive information; I'm just using it as a stored setting
for which kind of information to display on the page.
http://docs.python.org/lib/module-Cookie.html
That looks great!
Ciao, Michael.
Thanks Michael. :-)

--
John Gordon A is for Amy, who fell down the stairs
go****@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

Jul 24 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Amit D.Shinde | last post by:
Hello Experts.. I need some help regarding cookies and session objects and also global.asa file I am creating one cookie when a user logs in on my website. The cookie stores the login name of...
7
by: Marcus | last post by:
I know that when you start a session in PHP, the "cookie" it creates is not the same as those that are stored in your browser's temp folder, and instead is kept in RAM. I am confused because in...
24
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How can I see in javascript if a web browser accepts cookies?...
2
by: StanB | last post by:
I came across this weird problem: 1. Session state stops working after the app is deployed to another server because IE does not accept cookies. 2. It works if cookieless="true" in the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.