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
Stef:
Moving from one language to anther is not just a matter of
transliterating the code. Of you try that you will end up with a messy
code base that looks like PHP written in Python.
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
PyCon 2011 Atlanta March 9-17 http://us.pycon.org/
See Python Video! http://python.mirocommunity.org/
Holden Web LLC http://www.holdenweb.com/
cheers,
Stef
> regards
> Steve
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.
Come on Steve, I thought your role is to encourage / cheerlead here ;D
While you're absolutely right when it comes to complex apps and sites I
get the impression he's only talking about your common or garden short
admin scripts. I might be wrong though.
Roger
I'm quite happy to encourage, but I do find it necessary to interject a
warning from time to time. I was pretty sure someone with PHP knowledge
would come to the rescue.
> On 11/11/10 14:22, Stef Mientki wrote:
>> I can't find how th get to PHP's equivalent of $_Post and $_Cookie ?
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.
> Moving from one language to anther is not just a matter of
> transliterating the code. Of you try that you will end up with a messy
> code base that looks like PHP written in Python.
>
"The determined Real Programmer can write Fortran programs in any
language."
- from "Real Programmers don't use Pascal".
--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
They probably won't run quite as as fast, though.
--
Neil Cerutti
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
> > 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.
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.