is there an Python equivalent for the PHP super globals like $_POST,$_COOKIE ?

S

Stef Mientki

hello,

finally got Python running at my server.

Now I would like to replace the PHP server scripts with Python ( for easier maintenance).

But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ?
Google finds lots of links, but I can't find the answer.

thanks,
Stef Mientki
 
R

r0g

hello,

finally got Python running at my server.

Now I would like to replace the PHP server scripts with Python ( for easier maintenance).

But I can't find how th get to PHP's equivalent of $_Post and $_Cookie ?
Google finds lots of links, but I can't find the answer.

thanks,
Stef Mientki


PHP only tends to be run one way, the mod_php Apache module. There's
several ways run python in conjunction with a webserver like apache:
mod_wsgi, mod_python, CGI and FastCGI. I've never really looked into
this way of doing things but I guess the details are going to vary
depending on which one you use.

It's also not uncommon for python to actually BE the webserver too,
there's lots of webserver modules for python, cherrypy is fairly simple
and well regarded. Often you can proxy these through Apache to get the
benefits of both although again, that's not an approach I've used so I
can't really advise you further.

Roger.
 
R

Roy Smith

PHP is mostly a one-trick pony. It's meant to be run as a web scripting
language with Apache (or, I suppose, something else) on the front end.
As a result, a lot of web-specific things like $_Post and $_Cookie are
built into the language.

Python is intended to be more general purpose, so things which are built
in to other languages usually can be found in library modules. In this
case, you probably want to look at the SimpleHTTPServer module.

You may also want to look at any of several web application frameworks
such as Django, Pylons, etc. I'm guessing these are overkill for the
sorts of things you want to do, but they're worth at least browsing to
get some idea of what's out there.

For what it's worth, I've pretty much avoided PHP for all these years.
My latest gig, however, has had me doing PHP for the past 3 months or
so. The more I learn about PHP, the more I want to go running in the
other direction.
 
R

r0g

PHP is mostly a one-trick pony. It's meant to be run as a web scripting
language with Apache (or, I suppose, something else) on the front end.
As a result, a lot of web-specific things like $_Post and $_Cookie are
built into the language.

Python is intended to be more general purpose, so things which are built
in to other languages usually can be found in library modules. In this
case, you probably want to look at the SimpleHTTPServer module.


Actually when they say "Simple" they really mean it. The the
SimpleHTTPServer module doesn't parse form data at all. It's pretty easy
to get that using the urlparse module though...


def do_GET(self):
getvars = urlparse.parse_qs( self.path )
field1 = getvars[ "username" ][0]
field2 = getvars[ "password" ][0]
if authenticate( field1, filed2 ):
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write( "welcome" )
else:
self.send_response(404)
self.end_headers()
return

This may be lower level than you want really and does involve
permanently running a daemon on your server as opposed to the PHP way of
doing things (having Apache interpret PHP on a page by page basis).


My latest gig, however, has had me doing PHP for the past 3 months or
so.

That's terrible, you have my fullest sympathy in these difficult times.


Roger
 
R

Roy Smith

My latest gig, however, has had me doing PHP for the past 3 months or
so.

That's terrible, you have my fullest sympathy in these difficult times.[/QUOTE]

Actually, in a sick sort of way, it's fun. We regularly have PHP
bashing sessions in the office when somebody discovers yet another
depraved piece of language mis-design and we all get a good laugh out of
it. No all languages afford you the opportunity for this kind of
entertainment.

It's also quite educational. You can learn a lot about language design
by observing the mistakes that can be made.
 

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,710
Latest member
bernietqt

Latest Threads

Top