Ok, here's what I've got and it's driving me insane.  What I want to do 
is take a tracking number and grab the tracking data from the UPS web 
site.  I have a couple of questions though....

First of all, does anyone know if this is against UPS' TOS?  I read it 
but I didn't really see anything, of course IANAL, so I might have 
missed something.

Second, I assume this is best done using CURL.  I can get the shipment 
information just fine, but when I try to use the POST method to get the 
"Detailed Information" it does not display any of the detailed info, 
just some of the UPS page with some broken images.  I'm not concerned 
about getting images or anything else to show up, all I want is to be 
able to grab the data from the source.  Here's my code....any help 
would be greatly appreciated....

//This function gets the data....all you need is the tracking number
function GetUPSTrackingInfo($TrackingNumber1, $TrackingNumber2, 
$TrackingNumber3, $TrackingNumber4, $TrackingNumber5) {
        $TrackingNumber1=str_replace(" ","",$TrackingNumber1);
        $TrackingNumber2=str_replace(" ","",$TrackingNumber2);
        $TrackingNumber3=str_replace(" ","",$TrackingNumber3);
        $TrackingNumber4=str_replace(" ","",$TrackingNumber4);
        $TrackingNumber5=str_replace(" ","",$TrackingNumber5);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_PROXY, "http://my.proxy.server:3128";);
        curl_setopt($ch, 
CURLOPT_URL,"http://wwwapps.ups.com/WebTracking/processInputRequest?HTML
Version=5.0&sort_by=status&term_warn=yes&tracknums_displayed=5&TypeOfInq
uiryNumber=T&loc=en_US&InquiryNumber1=$TrackingNumber1&InquiryNumber2=$T
rackingNumber2&InquiryNumber3=$TrackingNumber3&InquiryNumber4=$TrackingN
umber4&InquiryNumber5=$TrackingNumber5&AgreeToTermsAndConditions=yes&tra
ck.x=30&track.y=4");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        $result=curl_exec ($ch);
        curl_close ($ch);
        echo $result;
}

function PostCurlPage ($pageSpec, $data) {
        $TrackingNumber=str_replace(" ","",$TrackingNumber);
        $agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)";
        $header[] = "Accept: 
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plai
n;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1";
        $header[] = "Pragma: no-cache";
        $header[] = "Connection: keep-alive";
        $header[] = "Referrer: 
http://wwwapps.ups.com/WebTracking/processInputRequest";;
        $ch = curl_init($pageSpec);
        curl_setopt($ch, CURLOPT_PROXY, "http://my.proxy.server:3128";);
        curl_setopt($ch, CURLOPT_USERAGENT, $agent);
        curl_setopt ($ch, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        $tmp=curl_exec ($ch);
        curl_close ($ch);
        //return $tmp;
        echo "$tmp";
}

$data="TypeOfInquiryNumber=T&tracknums_displayed=5&HTMLVersion=5.0&Agree
ToTermsAndConditions=yes&loc=en_US&sort_by=status&line1=DataSpecificToTr
ackingNumber&NumberDetailLines=1&tdts1_x=18&tdts1_y=10";
PostCurlPage("http://wwwapps.ups.com/WebTracking/processRequest",$data);

This doesn't work....I can't seem to figure it out.  I took out 
DataSpecificToTrackingNumber...but if you need it I'll send it your way.

GetUPSTrackingInfo("TheTrackingNumber","","","","");  Works just fine...




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to