OK, I've discovered how to use PHP to make Custom Shipping CGI scripts,
in case not everyone wants to use PERL. Unlike normal PHP scripts, this
one is run from the command-line (that was the trick that first eluded
me about the Custom Shipping module), so you need to have the shell
interpreter line at the beginning of the script. You also need to have
PHP-CLI installed (the PHP command-line interface), and you need to have
the PHP executable in the /usr/local/bin directory (or you have to alter
the following code to set the correct directory in the first line).
The following example script can easily be converted to a debugging
script by altering the if/then conditional so that it always performs
the "else" code, in which case it will dump all of the input parameters
to the error message which shows up in Shopsite (very handy when your
shipping module is behaving strangely and you're not sure why).
I'm not posting this to ask for help because I've already figured it out
on my own; I just thought I'd share because the official documentation
assumes that everyone wants to use PERL, and I've grown accustomed to
PHP. So without further ado, here's an example of a PHP-scripted Custom
Shipping module (I removed the actual rate calculations themselves in
order to save space, but they vary from installation to installation
anyway so they would be of little use to anyone but me):
#!/usr/local/bin/php -q
<?PHP
// Note: $_POST variable not available since this script is called as a
// CGI script, so we have to read in our params from stdin, with length
// determined by the CONTENT_LENGTH environment variable.
// Read in POST parameters sent by ShopSite
$stdin = fopen("php://stdin","r");
fscanf($stdin,"%{$SERVER['CONTENT_LENGTH']}s",$query_string);
// And now we split the params into the $params array.
parse_str($query_string,$params);
if ( $params['cust_country'] && $params['item_total'] )
{
// You would normally include code here for determining
// your shipping rates and options. Remember that all input
// parameters are in the $params array.
//
// The variables to set for the output (assuming you use the
// output code included in this example) are $status, $options,
// and $prices. $options and $prices are arrays.
}
else
{
$status="fail";
$error=urlencode("Params are ".var_export($params,true));
$option_count=0;
}
// Output data to ShopSite
echo "status=".$status."\n";
echo "option_count=".$option_count."\n";
if ($status="fail")
{
echo "error=".$error."\n";
}
for ( $option = 1; $option <= $option_count; $option += 1 )
{
echo "s".$option."option=".$options["$option"]."\n";
echo "s".$option."price=".$prices["$option"]."\n";
}
?>