PX : code

UPS Shipping Calculator by Shawn Van Der Poel
Download this code


<?
    /*********************
        send to ups program
        Send Vars
            $OriginPostalCode
            $DestZipCode
            $PackageWeight
            $upsProduct
            
        OUT VARS
            $result[0]
            
        UPS PRODUCT CODE (this should be in a drop down menu)
             Next Day Air Early AM         1DM
             Next Day Air                  1DA
             Next Day Air Saver             1DP
             2nd Day Air AM                 2DM
            2nd Day Air                     2DA
             3 Day Select                 3DS
            Ground                         GND
             Canada Standard                 STD
             Worldwide Express             XPR
             Worldwide Express Plus         XDM
             Worldwide Expedited             XPD

        UPS RATE CHART
            Regular+Daily+Pickup
            On+Call+Air
            One+Time+Pickup
            Letter+Center
            Customer+Counter

        Container Chart
            Customers Packaging            00
            UPS Letter Envelope            01
                or
            UPS Tube
            UPS Express Box                21
            UPS Worldwide 25kg Box        22
            UPS Worldwide 10 kg Box        23
            
        ResCom UPS Table
            Residential                    1
            Commercial                    2
            
    ***********************/
    
    $upsAction = "3"; //3 Price a Single Product OR 4 Shop entire UPS product range
    $upsProduct = "GND"; //set UPS Product Code See Chart Above
    $OriginPostalCode = "08053"; //zip code from where the client will ship from
    $DestZipCode = "08055"; //set where product is to be sent 
    $PackageWeight = "5"; //weight of product
    $OrigCountry = "US"; //country where client will ship from
    $DestCountry = "US"; //set to country whaere product is to be sent
    $RateChart = "Regular+Daily+Pickup"; //set to how customer wants UPS to collect the product
    $Container = "00"; //Set to Client Shipping package type
    $ResCom = "1"; //See ResCom Table
    
    $port = 80;
    $them = "www.ups.com";
    $workFile = "/using/services/rave/qcostcgi.cgi";
    $workString = "?";
    $workString .= "accept_UPS_license_agreement=yes";
    $workString .= "&";
    $workString .= "10_action=$upsAction";
    $workString .= "&";
    $workString .= "13_product=$upsProduct";
    $workString .= "&";
    $workString .= "14_origCountry=$OrigCountry";
    $workString .= "&";
    $workString .= "15_origPostal=$OriginPostalCode";
    $workString .= "&";
    $workString .= "19_destPostal=$DestZipCode";
    $workString .= "&";
    $workString .= "22_destCountry=$DestCountry";
    $workString .= "&";
    $workString .= "23_weight=$PackageWeight";
    $workString .= "&";
    $workString .= "47_rateChart=$RateChart";
    $workString .= "&";
    $workString .= "48_container=$Container";
    $workString .= "&";
    $workString .= "49_residential=$ResCom";
    $request = "$workFile$workString";
    $fp = fsockopen("$them", 80, &$errno, &$errstr, 30);
        if(!$fp) {
            echo "$errstr ($errno)<br>\n";
        }
        else {
            fputs($fp,"GET $request HTTP/1.0\n\n");
                while(!feof($fp)) {
                    $result = fgets($fp,500);
                    $result = explode("%", $result);
                    $errcode = substr("$result[0]", -1);
                        if ($errcode == "3") {
                            echo "$result[8]";
                        }
                        if ($errcode == "4") {
                            echo "$result[8]";
                        }
                        if ($errcode == "5") {
                            echo "$result[8]";
                        }
                        if ($errcode == "6") {
                            echo "$result[8]";
                        }            
                }
            fclose($fp);
        }
    
?>

Comments or questions?
PX is running PHP 5.2.17
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.