ryanfilard Posted July 21, 2011 Share Posted July 21, 2011 Here is my code, it is not working. <?PHP function USPSParcelRate($weight,$dest_zip) { $userName = '696RYANW7228'; $orig_zip = '11705'; $url = "http://Production.ShippingAPIs.com/ShippingAPI.dll"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_POST, 1); $data = "API=RateV3&XML=<RateV3Request USERID=\"$userName\"><Package ID=\"1ST\"><Service>PRIORITY</Service><ZipOrigination>$orig_zip</ZipOrigination><ZipDestination>$dest_zip</ZipDestination><Pounds>$weight</Pounds><Ounces>0</Ounces><Size>REGULAR</Size><Machinable>TRUE</Machinable></Package></RateV3Request>"; // send the POST values to USPS curl_setopt($ch, CURLOPT_POSTFIELDS,$data); $result=curl_exec ($ch); $data = strstr($result, '<?'); // echo '<!-- '. $data. ' -->'; // Uncomment to show XML in comments $xml_parser = xml_parser_create(); xml_parse_into_struct($xml_parser, $data, $vals, $index); xml_parser_free($xml_parser); $params = array(); $level = array(); foreach ($vals as $xml_elem) { if ($xml_elem['type'] == 'open') { if (array_key_exists('attributes',$xml_elem)) { list($level[$xml_elem['level']],$extra) = array_values($xml_elem['attributes']); } else { $level[$xml_elem['level']] = $xml_elem['tag']; } } if ($xml_elem['type'] == 'complete') { $start_level = 1; $php_stmt = '$params'; while($start_level < $xml_elem['level']) { $php_stmt .= '[$level['.$start_level.']]'; $start_level++; } $php_stmt .= '[$xml_elem[\'tag\']] = $xml_elem[\'value\'];'; eval($php_stmt); } } curl_close($ch); // echo '<pre>'; print_r($params); echo'</pre>'; // Uncomment to see xml tags return $params['RATEV3RESPONSE']['1ST']['1']['RATE']; } echo USPSParcelRate(10,11705); ?> Quote Link to comment https://forums.phpfreaks.com/topic/242586-get-shipping-rates-function-not-working/ Share on other sites More sharing options...
teynon Posted July 21, 2011 Share Posted July 21, 2011 More information is needed than "it is not working." What is it doing? Is it giving you an error? What happens? Quote Link to comment https://forums.phpfreaks.com/topic/242586-get-shipping-rates-function-not-working/#findComment-1245940 Share on other sites More sharing options...
ryanfilard Posted July 21, 2011 Author Share Posted July 21, 2011 Nothing appears Quote Link to comment https://forums.phpfreaks.com/topic/242586-get-shipping-rates-function-not-working/#findComment-1245941 Share on other sites More sharing options...
ryanfilard Posted July 21, 2011 Author Share Posted July 21, 2011 No text or error appears. Quote Link to comment https://forums.phpfreaks.com/topic/242586-get-shipping-rates-function-not-working/#findComment-1245944 Share on other sites More sharing options...
darkfreaks Posted July 21, 2011 Share Posted July 21, 2011 ran your function through a check this is what i got Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in CODE on line 26 Quote Link to comment https://forums.phpfreaks.com/topic/242586-get-shipping-rates-function-not-working/#findComment-1245947 Share on other sites More sharing options...
xyph Posted July 21, 2011 Share Posted July 21, 2011 Perhaps error reporting has been suppressed. Try using error_reporting( -1 ) If display_errors in php.ini is set to 0, set it to 1. Using ini_set( 'display_errors', 1 ) won't show parse errors, as the scripts are parsed before they are executed. Quote Link to comment https://forums.phpfreaks.com/topic/242586-get-shipping-rates-function-not-working/#findComment-1245948 Share on other sites More sharing options...
ryanfilard Posted July 21, 2011 Author Share Posted July 21, 2011 I have error reporting on. Nothing shows up. Quote Link to comment https://forums.phpfreaks.com/topic/242586-get-shipping-rates-function-not-working/#findComment-1245950 Share on other sites More sharing options...
xyph Posted July 21, 2011 Share Posted July 21, 2011 You've addressed a whole 50% of my solution. Try the other 50% Quote Link to comment https://forums.phpfreaks.com/topic/242586-get-shipping-rates-function-not-working/#findComment-1245953 Share on other sites More sharing options...
ryanfilard Posted July 21, 2011 Author Share Posted July 21, 2011 This is what I got Shipping: Strict Standards: USPSParcelRate() [function.uspsparcelrate]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Chicago' for 'CDT/-5.0/DST' instead in /home/samred/public_html/content/usps.php on line 62 Notice: Undefined index: RATEV3RESPONSE in /home/******/public_html/content/usps.php on line 62 Quote Link to comment https://forums.phpfreaks.com/topic/242586-get-shipping-rates-function-not-working/#findComment-1245956 Share on other sites More sharing options...
xyph Posted July 21, 2011 Share Posted July 21, 2011 There you go. In fact, your function is returning a variable that gets 'declared' as an array, and then nothing gets done with it. Did you write this function? If not, you should get support from the author. This is a forum for PHP programmers to get help. Quote Link to comment https://forums.phpfreaks.com/topic/242586-get-shipping-rates-function-not-working/#findComment-1245958 Share on other sites More sharing options...
ryanfilard Posted July 21, 2011 Author Share Posted July 21, 2011 I did not write this but I modified it a little because it was old. Quote Link to comment https://forums.phpfreaks.com/topic/242586-get-shipping-rates-function-not-working/#findComment-1245961 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.