1 / 17

Web Scripting [PHP] CIS166AE

Web Scripting [PHP] CIS166AE. Wednesdays 6:00pm – 9:50pm Rob Loy. Agenda. Rest of the year Web services overview RSS news Server side web service In-class: Own web service. Rest of the year. Nov 28 – Web Service (SOAP) Dec 5 – Object Oriented Programming & PHP Applications

leal
Download Presentation

Web Scripting [PHP] CIS166AE

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Web Scripting [PHP]CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy

  2. Agenda • Rest of the year • Web services overview • RSS news • Server side web service • In-class: Own web service

  3. Rest of the year • Nov 28 – Web Service (SOAP) • Dec 5 – Object Oriented Programming & PHP Applications • Dec 12 – OPTIONAL – Final Project Lab • Dec 14 – Final Projects Due

  4. Web Services Model WEBSITE DB WEB SERVICE USER

  5. IMPORTANT NOTE RSS is a standard for news across all platforms. This allows “readers” to display news the same from various sources. http://en.wikipedia.org/wiki/RSS

  6. RSS News http://rss.cnn.com/rss/cnn_world.rss

  7. RSS/XML <item> <title>Yemen's Saleh vows to step down as president</title> <link>http://rss.cnn.com/~r/rss/cnn_world/~3/6o9HGSh-ZcA/index.html</link> <description>Yemen&amp;apos;s embattled President Ali Abdullah Saleh will leave office &amp;quot;within 90 days&amp;quot; of an agreement with the regional Gulf Cooperation Council, he said in an interview</description> <pubDate>Tue, 15 Nov 2011 05:18:48 EST</pubDate> </item>

  8. Consuming RSS with PHP(1) $ch = curl_init("http://sports.espn.go.com/espn/rss/nfl/news"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, 0); $data = curl_exec($ch); curl_close($ch); $doc = new SimpleXmlElement($data, LIBXML_NOCDATA); parseRSS($doc); http://ditio.net/2008/06/19/using-php-curl-to-read-rss-feed-xml/

  9. Consuming RSS with PHP(2) function parseRSS($xml) { echo "<h2>".$xml->channel->title."</h2>>\n"; $cnt = count($xml->channel->item); for($i=0; $i<$cnt; $i++) { $url = $xml->channel->item[$i]->link; $title = $xml->channel->item[$i]->title; $desc = $xml->channel->item[$i]->description; echo “<p><a href=\””.$url.”\”>”.$title.”</a>”; echo $desc.”</p>\n”; } } http://ditio.net/2008/06/19/using-php-curl-to-read-rss-feed-xml/

  10. RSS Options #2 • $xml = "http://www.nytimes.com/services/xml/rss/nyt/business-computing.xml"; • $xmldocument = new DOMDocument(); • $xmldocument->load($xml); • $source = $xmldocument-> • getElementsByTagName('channel')-> • item(0); • $sourcetitle = $source-> • getElementsByTagName('title')-> • item(0)-> • childNodes-> • item(0)-> • nodeValue; • echo $sourcetitle; • $story = $xmldocument-> • getElementsByTagName('item'); • for ($x = 0; $x < 5; $x++) • { • $title = $story-> • item($x)-> • getElementsByTagName('title')-> • item(0)-> • childNodes-> • item(0)-> • nodeValue; • $link = $story-> • item($x)-> • getElementsByTagName('link')-> • item(0)-> • childNodes-> • item(0)-> • nodeValue; • $description = $story-> • item($x)-> • getElementsByTagName('description')-> • item(0)-> • childNodes-> • item(0)-> • nodeValue; • $date = $story-> • item($x)-> • getElementsByTagName('pubDate')-> • item(0)-> • childNodes-> • item(0)-> • nodeValue; • echo "<p><a href=\"" . $link. "\">". $title . "</a></p>\n"; • echo "<p style=\"font-size:12px;\">" . $description . "</p>\n"; • echo "<p>" . $date . "</p>\n"; • echo "<hr />"; • }

  11. PHP Client Side WS // Pull in the NuSOAP code require_once('../lib/nusoap.php'); // Create the client instance $client = new nusoap_client('http://www.robloy.com/soap/server.php'); // Call the SOAP method $result = $client->call('hello', array('name' => 'Scott', 'age'=> '12')); // Display the result echo '<h2>Result</h2><pre>'; print_r($result); echo '</pre>'; http://www.codedeveloper.net/2010/05/nusoap-soap-php-web-services-tutorial-part-one/

  12. PHP Server Side WS // Pull in the NuSOAP code require_once('../lib/nusoap.php'); // Create the server instance $server = new soap_server; // Register the method to expose $server->register('hello'); // Define the method as a PHP function function hello($name, $age) { return 'Hola, ' . $name . ', you have $'. $age;} // Use the request to (try to) invoke the service $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; $server->service($HTTP_RAW_POST_DATA); http://www.codedeveloper.net/2010/05/nusoap-soap-php-web-services-tutorial-part-one/

  13. Weather Web Service • <?php • $url ="http://w1.weather.gov/xml/current_obs/KSDL.xml"; • $xml = simplexml_load_file($url); • echo "<h1>Phoenix Weather</h1>"; • echo $xml->weather . "<br />"; • echo $xml->temperature_string . "<br />"; • echo $xml->wind-speed . "<br />"; • echo $xml->relative_humidity. "%<br />"; • ?>

  14. IMPORTANT NOTE In PHP you can build both the Client and Server piece of a Web Service. Any other language/site can access a web service using HTTP. For example an .NET application can call a PHP web service.

  15. Questions?

  16. Lab • Make an web service that determines how much to leave for a 15% tip (tipcalculator.php) • Make a web page that a user inputs bill amount and calls the tip calculator to print out the bill, tip and total amounts. • Email URL to rob.loy@scottsdalecc.edu by Dec 5 at 6:00pm

  17. Final Project • Create a PHP website using pieces of code and modules we learned in class • Make the site look like a finished product that you can share as a indication of your skills • You will be graded on looks, details and demonstration of php knowledge • Send email to rob.loy@gmail.com with URL to input form file before 6pm on Dec 14.

More Related