adding php files for second exercise
This commit is contained in:
parent
872ed812ca
commit
a914a910d0
11
src/02-shipping/docroot/plainHttpService.php
Normal file
11
src/02-shipping/docroot/plainHttpService.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
// shipping.php contains our get_shipping_options($zipcode, $pounds) function.
|
||||
// It returns an array mapping service name to price in US dollars.
|
||||
require ('shipping.php');
|
||||
|
||||
$options = get_shipping_options($_REQUEST[zipcode], $_REQUEST[pounds]);
|
||||
foreach ($options as $service => $price) {
|
||||
$result[] = "$service: $price USD";
|
||||
}
|
||||
print implode("\n", $result);
|
||||
?>
|
12
src/02-shipping/docroot/shipping.php
Normal file
12
src/02-shipping/docroot/shipping.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
// Returns an array of made-up shipping options.
|
||||
function get_shipping_options($zipcode, $pounds) {
|
||||
$baseCost = round($zipcode / 10000) + ($pounds * 5);
|
||||
$options = array( "Next Day" => $baseCost * 4,
|
||||
"Two Day Air" => $baseCost * 2,
|
||||
"Saver Ground" => $baseCost);
|
||||
return $options;
|
||||
}
|
||||
|
||||
?>
|
15
src/02-shipping/docroot/xmlHttpService.php
Normal file
15
src/02-shipping/docroot/xmlHttpService.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
// shipping.php contains our get_shipping_options($zipcode, $pounds) function.
|
||||
// It returns an array mapping service name to price in US dollars.
|
||||
require('shipping.php');
|
||||
|
||||
$options = get_shipping_options($_REQUEST["zipcode"], $_REQUEST["pounds"]);
|
||||
|
||||
$results[] = "<options>";
|
||||
foreach ($options as $service => $price) {
|
||||
$results[] = "<option><service>$service</service><price>$price</price></option>";
|
||||
}
|
||||
$results[] = "</options>";
|
||||
print implode("\n", $results);
|
||||
?>
|
Loading…
Reference in New Issue
Block a user