UPS XML Rate PHP script

UPS XML Rate PHP script
3 votes, 4.33 avg. rating (87% score)

I did not think that this old php script is still interested by someone. Anyway, I received an inquiry today that my upsrate script’s result does not match with UPS homepage’s result.

Actually, they generate the same result if you provide the same option. Those options were not available to choose in the original upsrate script. I updated it today that you can try the script more easily.



24 thoughts on “UPS XML Rate PHP script

  1. Hi, you’ve saved me!!!!, this script will save me alot of work.

    By the way I think you’ve got to check the Weigth field the legend seems to say that it’s for pounds,
    but I think you actually send Kg, maybe you forgot to do the conversion from pounds to Kg when you did this
    version of the script.

    Anyway thanks a lot!!!!

  2. Hi, I’ve been customizing and testing your form, and I’ve found 2 miskates that have been driving me crazy
    for a while, it’s to change the “Schipping To” adress. First you missed one equal symbol:

    if($s_zip==” || $s_country==” || $t_zip==” || $t_country=” || $weight==”){
    $error_msg=”please provide all information”;

    “$t_country=”” you know you’re doing an asignation instead of a comparation.

    You also misspelled the $t_country to check if it has been set.
    You wrote
    if ($t_coutnry == ” ) $t_country=’US’;
    instead of
    if ($t_country == ” ) $t_country=’US’;

    I hope having halped you as you’ve helped me, and thanks again.

  3. I’m trying to get this to work with my web page. I tryied running it as is (execept for my passwords) at it seems to lock up after I submit the request for a price. I use godaddy lunix servers and I’m fairly sure that they have _curl enabled on all their lunix servers. Is their somthing else I need to change to make this work?

  4. You can test if curl module is compile in by using “phpinfo()” function. Please take a look at the PHP /Webserver log for any clue. Also you may want to test with console ‘curl’ command first.

  5. curl
    CURL support enabled
    CURL Information libcurl/7.10.6 OpenSSL/0.9.7a ipv6 zlib/1.2.3

    The phpinfo() gave me the above info about CURL. So I guess that isn’t the problem. If I had the worng password or key would that cause the problem? That make you just through hoops a ups hand kive you developer keys/ developer user name, xml keys. If i’m using the wrong username or key would that cause it to hang? Thanks for any insite.

  6. HanaDaddy, You script works great. My problem was the godaddy servers blocking any type of 3rd party web site (ie. UPS). godaddy wants me to upgrade to the dedicated or virtual dedicated servers for $50 dollars a month (haha). I switch servers to someone else and all is well! thanks.

  7. I must say that this script is a life saver in every possible way. I have gone thru so many over the last few months. The problem I ran into was my server does not handle asp. Just about every good working cal script out there is based on asp.

    Again, thank you for your great work.

  8. Thanks for this wonderful class! Even though it may be “old” it still works a charm! Helped me quickly and easily estimate rate calculations into a project of mine.

    Cheers!

  9. Thank for sharing.
    I’ve research on PHP + XML UPS Online Tools for whole day.

    It seems this is the correct package that I really needs. Many Thanks.

  10. this is absolutely great stuff. great work, i commend you! at first i could not get this to work and was about ready to give up but i looked through the .pdf document UPS provides for the rate and service selector. there is no php in that sdk but i did pick up on something interesting and decided to give it a try. i noticed the example url they say to to try for curl is: https://wwwcie.ups.com/ups.app/xml/Rate. in the code that is provided above, the url was identical except it was http://www.ups….. . once i changed it to wwcie then POOF! it worked! not sure why but i thought i would post this on here in case it is an issue for someone else.

  11. i know i was more shocked than the next person that it worked. oh well! probably some configuration on our server or something. lucky break, i guess 🙂

  12. Right out of the box your software worked 1st time!! I have a web store that is written in perl and I was wondering how much of a hassle would it be to get you output into perl?

    Thank you for making your program available to all.

    Walter

  13. bob, i believe all ups ground shipments are guaranteed for 5 days but it is a very loose guarantee at that. if you wanted to use the 5 days as an expected transit time i think you’re going to have to make that calculation in php before it is outputted into html.

  14. Thanks a lot
    It is very helpful for php developer and easy way to integrate with UPS.
    I searched a lot but find it better than other.

    Thanks again

  15. Old script or not, this one works very well!
    The only thing I haven’t figured out, and I don’t know if it’s even possible, but is there a way the script can return results only on specific shipping methods of my choice? I only offer a few different options since the product I sell doesn’t warrant any kind of expedited overnight kind of shipping. I tried eliminating some of the choices in the ups_service array, but the pricing still shows up.
    I appreciate any help.
    Thanks

  16. Hello thank you for your comment.
    Actually I am not sure how to provide the multiple service types in the request even though you can do it if you want just one service type.

    // in ups.php
    //US ORIGIN
    $ups_service = array<|$styles>|> ( 
    	'01' => 'UPS Next Day Air',
            '02' => 'UPS 2nd Day Air',
    	'03' => 'UPS Ground',
    	'07' => 'UPS Worldwide Express',
    	'08' => 'UPS Worldwide Expedited',
    	'11' => 'UPS Standard',
    	'12' => 'UPS 3 Day Select',
    	'13' => 'UPS Next Day Air Saver',
    	'14' => 'UPS Next Day Air Early A.M.',
    	'54' => 'UPS Worldwide Express Plus',
    	'59' => 'UPS 2nd Day Air A.M.',
    	'65' => 'UPS Express Saver',
       );

    If you just want ‘UPS Ground’ , use ’03’ for the service type (The first argument of the rate member function)

      $ups_rates=$ups->rate('03',$t_zip,'',$t_country,$weight,$residential);

    You can also filter out the XML results if you want to show more than one service types.

     for<|$styles>|>($i=0;$i<$ct;$i++){
    if<|$styles>|> ($ups_rates[$i][service] == '03'  | $ups_rates[$i][service] == '11' ) {  
      echo<|$styles>|> "<tr><td>".$ups_service[$ups_rates[$i][service]]."</td>";
      echo<|$styles>|> "<td>\$".number_format<|$styles>|>($ups_rates[$i][basic],2)."</td>";
      echo<|$styles>|> "<td>\$".number_format<|$styles>|>($ups_rates[$i][option],2)."</td>";
      echo<|$styles>|> "<td>\$".number_format<|$styles>|>($ups_rates[$i][total],2)."</td>";
      echo<|$styles>|> "<td>".$ups_rates[$i][days]."</td>";
      echo<|$styles>|> "<td>".$ups_rates[$i][time<|$styles>|>]."</td></tr>";
     }
    }
  17. Hi,
    thanks a lot for the code. You are very generous. By the way, i found out that rate for UPS Express Saver is not the same at on UPS website. Can you find out why? Thank you so much

Leave a Reply

Your email address will not be published. Required fields are marked *