PHP session equivalent?

E

Erik Johnson

There are a lot of things about PHP I was not too keen on and hence why
my company is primarily doing Python these days, but one thing I was quite
impressed with was the ease with which it provided session functionality...

<?php

session_start();
session_register['my_var'];

$my_var = "whatever";

?>

And then in another CGI script do basically the same thing and get the
value of $my_var back. Setting of a session ID cookie happens automagically.
This is quite handy and simple.

I don't think it's quite so simple in Python (which is not to say I
think PHP is better than Python). Doing a little extra work is no big deal,
but could someone be so kind as to lay out what needs to be done for a
Python CGI script to get essentially the same functionality? Are there
Python modules that implement a lot of this already?

We are currently running under an Apache server (on SuSE Linux 8.2). I'm
not clear on whether some session functionality is provided there? We may be
moving to Zope before too long (trying to find some time to evaluate it), so
a method that is not strictly dependent on Apache would be preferable (in
the short term that may suffice).

Thanks for taking the time to read my post! :)

-ej
 
W

Walter Burleigh

Erik said:
There are a lot of things about PHP I was not too keen on and hence
why
my company is primarily doing Python these days, but one thing I was quite
impressed with was the ease with which it provided session
functionality...

Like you I think it is a big plus of PHP as a beginner's web development
tool that it provides session management out of the box. It would certainly
make python more attractive for beginners if they could use session
management out of the box, too. (I know that there are lots of web
development frameworks, but they are to be too difficult to learn, if you
are new to web development).

There is no module for session management in the python standard library.
But there are lots of python frameworks that would do this job well (my
favorite: cherrypy). If you think that a whole framework would be overkill,
you either could try to recylce the session part of an existing framework,
or you could write a module for yourself.

I have written a module which is quite similar to the php session
management, except for that it does no url rewriting when cookies are not
allowed. If you are interested, I will mail you a copy.
 
R

Reinhold Birkenfeld

Walter said:
Like you I think it is a big plus of PHP as a beginner's web development
tool that it provides session management out of the box. It would certainly
make python more attractive for beginners if they could use session
management out of the box, too. (I know that there are lots of web
development frameworks, but they are to be too difficult to learn, if you
are new to web development).

There is no module for session management in the python standard library.
But there are lots of python frameworks that would do this job well (my
favorite: cherrypy). If you think that a whole framework would be overkill,
you either could try to recylce the session part of an existing framework,
or you could write a module for yourself.

I have written a module which is quite similar to the php session
management, except for that it does no url rewriting when cookies are not
allowed. If you are interested, I will mail you a copy.

If you need session management, and do not want a complicated web app
framework, check out pso: http://pso.sf.net

Reinhold
 
J

Jason F. McBrayer

Erik Johnson said:
I don't think it's quite so simple in Python (which is not to say I
think PHP is better than Python). Doing a little extra work is no big deal,
but could someone be so kind as to lay out what needs to be done for a
Python CGI script to get essentially the same functionality? Are there
Python modules that implement a lot of this already?

Take a look at jonpy (jonpy.sourceforge.net). jon.session does pretty
much exactly what you want. There are lots of other python web
frameworks that also provide this, but jonpy is one of the smallest
and conceptually simplest.
 

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,969
Messages
2,570,161
Members
46,709
Latest member
AustinMudi

Latest Threads

Top