1. Home
  2. Computing & Technology
  3. Python

Using PHP and Javascript instead of CGI

From Al Lukaszewski, for About.com

6 of 9

PHP as a CGI stand-in

Now we need to create the PHP script that will channel communication between our Python program and the web page. The basic code is below.

We will discuss this script on the next page. If you would like to keep the code to hand for reference, copy it into your favorite editor or open this page in a new window.

<?php
$results = shell_exec ("./search \"" . $_POST["word"] . "\" 3") ;

print "
<html>
<head>
<title> About.com's Python Program Results.</title>
<link rel=\"stylesheet\" type=\"text/css\" href=\"./myway.css\" />
</head>
<body>

<div class=\"search\">
<form action=\"search.php\" method=\"post\">
<h5>Search <br>
<input type=\"text\" name=\"word\" size=\"20\" onChange=\"submit(word)\"><br>
<!-- <input type=\"submit\" value=\"Submit\" /> </h5> -->
</form>
</div>

<h1 class=\"welcome\"> Welcome to Python with PHP and Javascript </h1>

<h6 class=\"maintext\"> ";

print $results;
print "</h6> </body> </html>";
?>

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 - PHP as a CGI stand-in

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

All rights reserved.