1. Home
  2. Computing & Technology
  3. Python

Using PHP and Javascript instead of CGI

From Al Lukaszewski, for About.com

7 of 9

Looking at the PHP script: Part 1

All PHP scripts begin with '<?php' and end with '?>'. When set within a page of HTML , these indicators tell the computer where to differentiate between HTML and PHP.

The next line is a PHP statement that does three things. It takes the form data from the web page and forms a terminal command, a system call, from it, passing the form data to the Python program as a command line argument. The trailing '3' is simply the second argument for the Python program, sys.argv[2]. Where CGI requires a bit of hacking to handle multiple options, PHP allows you to hardwire options into the script, thus allowing you to call the same script in different ways from various pages.

This system call is then executed using the PHP command 'shell_exec()', which runs the Python program and returns the output. This output is then assigned to the variable '$results'. It is important to note that variables in PHP start with a dollar sign ('$') and that all PHP statements must end with a semi-colon (';').

Explore Python
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Python
  4. Web Development
  5. PHP and Javascript for CGI - Looking at the PHP script: Part 1

©2009 About.com, a part of The New York Times Company.

All rights reserved.