CGI Examples
Example 1 - telling the time
This is a simple example of a CGI script which when requested produces
a HTML page which contains the current time.
sh version
#!/bin/sh
echo "Content-Type: text/html"
echo
echo
echo ""
echo "The date is `date`."
echo "
This page was dynamically generated by a CGI script"
Perl version
#!/usr/local/bin/perl
$date=`date`;
print "Content-Type: text/html\r\n\r\n";
print "The date is `$date'";
print "
This page was dynamically generated by a CGI script";
C version
#include
#include
#include
#include
/* Returns the date */
char *date() {
time_t tloc;
if(time(&tloc) == (time_t) -1) perror("time()");
return ctime(&tloc);
}
int main() {
printf("Content-Type: text/html\r\n\r\n");
printf("The date is `%s'",date());
printf("
This page was dynamically generated by a CGI script");
}
Back to CGI index