Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ITM352_Server_Side_Processing.pdf

dport96
September 11, 2014
83

 ITM352_Server_Side_Processing.pdf

dport96

September 11, 2014
Tweet

Transcript

  1. Today's Class • What is PHP? • Diving in head

    first! – How PHP enables server side dynamic web pages – Starting to figure out what application programming is about… Have confidence that you will get the job done! Just keep at it.
  2. What is PHP? • A web-based programming language – "Pre-Hypertext

    Processor" or “PHP- Hypertext Processor” (although it originally meant “Personal Home Page”) - All computers are directed by programs - like very detailed recipes - written in languages that humans can understand and be processed by computers (unlike English) PHP is one among many thousands of such languages…
  3. What's special about PHP? • Web-based, familiar user interfaces, easy

    integration with other web-based systems • Current, designed according to the latest understanding of programming language design. • Portable, so it can be run on almost any computer. • Object-oriented, like the most popular languages (Java, C++) used today for the most innovative applications. • Convenient, loaded with powerful and useful features, supports many different programming styles • Used, lots of PHP in use today (incl. the most "popular" dynamic web sites), more all the time, lots of non-trivial examples and free resources • Not Proprietary, and that’s good!
  4. How Does PHP Work? • PHP is a program that

    performs dynamic HTML scripting – It is a language interpreter that directly executes commands then ultimately outputs into HTML/HTTP (rather than a compiler which outputs translates commands into machine code for later execution) – The server knows to execute PHP code when the requested file has a .php extension HTML + PHP code PHP Scripting Engine Static HTML output Dynamic data (files, database, webserver, data feeds, etc.) Web Server (e.g. Apache) Client (e.g. IE) Give me page xxx.php Must have .php extension!
  5. Example Dynamic Web Page • Open your favorite text editor

    and type <?php echo '<big><center> Hello World!</center><BR>'; echo '1+2='; echo 1+2; ?> Note that PHP code will always be enclosed inside the <? … ?> or <?php … ?> tags. Outside is HTML (but notice that inside there can be HTML too) • Questions – Why is this a "dynamic" web page? – Why wouldn't this file work the same if you called it index.html? – When you do a "view source" in the browser, where is the PHP code?
  6. Tour of a PHP IDE: Simple Output • Several parts

    to an IDE (for us, NetBeans for PHP) – Editor (for writing code) – File manager – Preview (web-server, web-browser) – Tools (documentation, debugger, scripts, etc.) In the IDE, let’s type and run the following: <big><center> Hello World!</center><BR> 1+2= <?php // add 1 and 2 then print out the result echo 1+2; ?> • Why is this the same as the previous dynamic web page example?
  7. Server Side PHP Page with current date <big><center> The date

    is:</center><BR> <?php echo date(DATE_RFC2822); ?> -Who’s date is used? -What if the server were in a different time zone? Page redirection <?php header('Location: http://www.google.com'); ?> -In JavaScript window.location = 'http://www.google.com'; -HTML <META http-equiv="refresh" content="0;URL=http://www.google.com"> Note how this HTML is just “passed” though the PHP scripting engine What’s the difference?
  8. Client vs. Server Side Processing • What’s the difference? Client

    Side Server Side • Can directly manipulate page objects • Can manipulate web server behavior e.g. page processing • No network communication needed • Secures data and actions away from users • Local user data from client only • User data can be shared for any client • Can “guard” data for validation before submission for quick recovery • Process data from clients • Can access shared data and services (files, databases, other servers, processes, etc.)
  9. Libraries and Frameworks Both PHP and JavaScript have many useful

    frameworks and libraries to help you do just about anything! PHP: php.net/manual/en/extensions.alphabetical.php pear.php.net/packages.php, <see NetBeans project> JavaScript: DOM, JQuery, Angular, AJAX, COMET, DataTables, etc. <see NetBeans project>
  10. Client + Server Side Processing Compare dates Server Time: <?php

    echo date(DATE_RFC2822); ?> <br> Browser Time: <script> document.write( Date().toString() ); </script> Generating JavaScript with PHP Make a page that generates a random color <script> <?php echo "document.body.style.backgroundColor= 'rgb(" . rand(0,255) . ',' . rand(0,255) . ',' . rand(0,255) . ")';" ?> </script>