Brinkster Knowledge Base
PHP call out to cgi-script example
<?php
$data = file_get_contents("http://username.brinkster.net/cgi-bin/time.cgi",0);
echo $data;
?>
C Source Code:
#include <time.h>
#include <stdio.h>
main()
{
time_t t;
time(&t);
printf ("Content-type: text/html");
printf ("\n");
printf ("\n");
printf ("<html>");
printf ("<head>");
printf ("<title>Test</title>");
printf ("</head>");
printf ("<body>");
printf ("Seconds: ");
printf ("The current Date and Time is: %s", ctime(&t));
printf ("\n");
printf ("</body>");
printf ("</html>");
}
Items to note: The C code was compiled and tested using GCC, however it should compile with just about any standard C compiler. Also, on Pro and Advanced Brinkster Shared Linux accounts the example C code can be compiled using GCC and put into the cgi-bin directory with file permissions of 750. The compiled C code should be renamed with a .cgi extension and put into the user's cgi-bin. The php script should be uploaded to the public_html folder in the same manner as any other php script on Brinkster's servers. To confirm it is working browse to the location the example php script was uploaded to (http://username.brinkster.net/test.php).