RE: [PHP] UPSOnline

From: Date: Sun, 10 Sep 2000 03:10:51 +0000
Subject: RE: [PHP] UPSOnline
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-16022@lists.php.net to get a copy of this message
Glover, I just wrote some code to interface with the UPS Online Tools. The program might not be perfect, but it's been working well for me. //******************************************* function get_ups_amount($svc_type,$zip_from,$zip_to,$country_to,$weight,$is_res, $pickup_type,$pack_type){ $content = "AppVersion=1.2&AcceptUPSLicenseAgreement=YES&ResponseType=application/x-ups -rss&". "ActionCode=3&ServiceLevelCode=".$svc_type."&RateChart=".$pickup_type."&Ship perPostalCode=". $zip_from."&ConsigneePostalCode=".$zip_to."&ConsigneeCountry=".$country_to. "&PackageActualWeight=$weight&ResidentialInd=$is_res&PackagingType=$pack_typ e"; $content_length = strlen($content); $fp = fsockopen("www.ups.com",80,&$error_num,&$err_desc,300); if($fp){ set_socket_blocking($fp,TRUE); fputs($fp, "POST /using/services/rave/qcost_dss.cgi HTTP/1.0\r\n". "content-type: application/x-www-form-urlencoded\r\n". "content-length: $content_length \r\n\r\n". $content); while(!feof($fp)){ $result .= fgets($fp,4096); } fclose($fp); $res_fields = split("\r\n",$result); while(list($key,$value) = each($res_fields)){ if(substr($value,0,9) == 'UPSOnLine'){ $fields = split('%',$value); } } $ret_code = $fields[2]; $ret_msg = $fields[3]; $rate = $fields[12]; } if($ret_code == '0000'){ return $rate; } else { return -1; } } //******************************************* Typical usage would be like: $shipping = get_ups_amount('GND','94105','60616','US',10,1,'Regular+Daily+Pickup','00'); This would return the shipping amount to ship a package * by Ground * from the shipper's zip code of 94105 * to the recipient's zip code of 60616 * in the US * weighing 10 pounds * to a residential address * where UPS regularly picks up packages from the shipper * using packaging materials provided by the shipper and not UPS The function returns -1 if an error code was returned by UPS. Service type (i.e. 1DA=Next Day Air) and other codes can be found in the Rating and Service Selection Datastream section of the UPS Online Tools Documentation. Hopes this helps. Clincy Latimer Solon Systems LLC clincy@solonsystems.com -----Original Message----- From: Glover George [mailto:dime@gulfsales.com] Sent: Thursday, September 07, 2000 12:12 PM To: php-general@lists.php.net Subject: [PHP] UPSOnline Hello. I was wondering has anyone had any experience with UPSOnline Tools and PHP. UPSOnline tools is a system that allows you to query ups's servers for rates and such. I would like to implement this into my php pages for ordering. Here's what I think I need to know. I understand that all of the messages are done in HTTP headers. You send a header with the request in it to their server on port 80, and it replies with the answer (if everything is successful). Well, I'm not too familiar with headers. My extent of knowledge of them is the php function header("Location:http://www.somewhere.com"); for redirecting clients. How do I send these headers and how do I recieve the response. Any tips would be highly appreciated. Thanks. Glover George Systems/Networks Admin Gulf Sales & Supply, Inc. dime@gulfsales.com

« previous php.general (#16022) next »