[ Team LiB ] Previous Section Next Section

Calling an External CGI Script with the virtual() Function

If you are converting a site from plain HTML to PHP-enabled pages, you might have noticed that your server-side includes no longer work. If you are running PHP as an Apache module, you can use the virtual() function to call CGI scripts, such as Perl or C Web counters, and include their output in your pages. Any CGI script you write must output HTTP headers.

Let's write a simple Perl CGI script. If you don't know Perl, don't worry about this. It simply outputs an HTTP header and all the environmental variables available to it:


#!/usr/bin/perl -w
print "Content-type: text/html\n\n";
foreach ( keys %ENV ){
  print "$_: $ENV{$_}<br />\n";
}

Assuming that this script is saved in an executable file called test.pl in a cgi-bin directory, you can now call it with the virtual() function, including its output in your PHP document:


<?php
virtual("/cgi-bin/test.pl");
?>


    [ Team LiB ] Previous Section Next Section