how to handle two forms in cgi?

Steve Holden steve at holdenweb.com
Sun Dec 4 04:59:49 EST 2005


lli at sos.state.tx.us wrote:
> Hi Dan,
> 
> Sure. You are right. When I correct this according to your idea, it
> works now. Thank you very much. But I have second problem. When users
> run second form, other people can see adress in users' browers and know
> how to run the second form, so they don't need to run login form. How I
> can handle this case? How I can let users run login form firstly, then
> they can run second form(search form)?
> 
> By the way I use python to write cgi.
> 
> Any help is appriciated!
> 
I'm afraid you are running into what are called "session state" 
problems. In other words, your system needs to be able to "remember" 
that a user has already successfully visited one page before allowing 
them to visit another.

There are various ways to solve this problem, but most of them revolve 
around maintaining state information for each different concurrent user 
of your web. Once a user successfully logs in your record "logged in = 
True" or similar in your session state memory, and at the start of each 
CGI script for which the user is required to be logged in you actually 
check the state memory to verify that is the case.

There are various mechanisms for maintaining session state, many of 
which rely on serving a cookie to each user's browser. This allows your 
server to identify which session any particular request is a part of.

See if

   http://starship.python.net/crew/davem/cgifaq/faqw.cgi?req=all#2.11

makes any sense to you. If not, you might want to Google around a bit 
for things like "Python web session" to see what you can find.

Note there are plenty of web frameworks (e.g. CherryPy, mod_python) that 
offer assistance with maintaining session state, but it isn't impossible 
to maintain it yourself in CGI scripts once you understand the problem. 
Good luck!

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC                     www.holdenweb.com
PyCon TX 2006                  www.python.org/pycon/




More information about the Python-list mailing list