Jump to content

Recommended Posts

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);

?>

 

Link to comment
https://forums.phpfreaks.com/topic/242586-get-shipping-rates-function-not-working/
Share on other sites

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.

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.