I want to utilize PHP for cgi. I.e. I want to write in php (no output to screen or user) to perform various functions.
How does ShopSite call a cgi-script. I.e is it done directly through the web-server as a POST (if so, I should just be able to use any php file with a .php extension). Or does it do it through a shell interpeter (in this case, seems I would need an interpeter header like '#!/usr/local/bin/php -q'.
I try to account for POSTed info to come either on stdin or via the PHP $_POST variable (precedence given to stdin).
Can anyone advise? I've read the posts that state you can't use .php in cgi-bin. But if it's interpeted b the the shell or the kernel, it should acknowlege the magic_number (from my old Unix days) of '#!/usr/local/bin/php'.
Help please.
script I'm trying as an experiment is below. But don't want to break a customer's site if it would blow up.
[code]
#!/usr/local/bin/php -q
<?php
echo "Content-type: text/html\n\n";
$sendMail = TRUE;
$usePost = TRUE;
$useStdIn = TRUE;
function preOut($str) { echo "$str\n"; }
$postParams = array();
$subject = 'Order get/post for ShopSite';
$to = 'tonyb@1sit.com';
$from = 'noone@example.com';
$cc = '';
$headers = "From: $from\r\n".($cc ? "Cc: $cc\r\n" : "");
$body = '';
$gotFrom = 'No One';
if( $useStdIn ) {
$stdin = @fopen("php://stdin", "r");
$postString = @fread($stdin, $_SERVER['CONTENT_LENGTH']);
@parse_str($postString, $postParams);
if( $postParams )
$gotFrom = 'Stdin';
}
// If there was nothing on stdin, then see if $_POST is set, has elements and that we didn't end up with postParms set
// from using stdin.
if( $usePost && isset($_POST) && count($_POST) && !$postParams) {
$postParams = $_POST;
if( $postParams )
$gotFrom = '_POST';
}
$body .= "\nPost Parameters from $gotFrom:\n";
foreach($postParams as $name => $value)
$body .= sprintf("\t%20s: %s\n", $name, $value);
if( $sendMail )
mail($to, $subject, $body, $headers);
?>
[/code]