[Tutor] Stopping program execution
Sean Abrahams
Sean Abrahams <sa@sfsu.edu>
Thu Jan 30 19:09:47 2003
I have a web script that checks to see if the user has a session
cookie. If not, I want to display a page saying 'no session found,
please login. yadda yadda yadda', and not execute the rest of the
script. Thing is, I check for the session cookie through a separate
module.
import session
id = session.checkSession()
# for example
If there is a session, the id is returned, otherwise the error message
is printed.
Right now, I have the error message printing fine, but it continues to
execute the rest of the script, which is not the behavior I'm looking
for.
How do I halt the script when it detects no session? Or, is there a
better way to do this?
def sessionCheck(session):
try:
id = session["id"]
return id
except KeyError, e:
print "content-type: text/html"
print
print "No session found."
# Stop script
Thanks,
--Sean