1 / 64

CS 482 Web Programming and Scripting

CS 482 Web Programming and Scripting. Week 6 – Installing Apache, PHP, MySQL and Using the Software. Topics. Apache Web Server PHP MySQL. Introduction. Web server Responds to client requests by providing resources such as XHTML documents

delano
Download Presentation

CS 482 Web Programming and Scripting

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. CS 482 Web Programming and Scripting Week 6 – Installing Apache, PHP, MySQL and Using the Software

  2. Topics • Apache Web Server • PHP • MySQL

  3. Introduction • Web server • Responds to client requests by providing resources such as XHTML documents • Web server maps the URL (Uniform Resource Locator) to a resource on the server and returns the requested resource to the client • Web server and client communicate with platform-independent Hypertext Transfer Protocol (HTTP)

  4. HTTP Request Types • Request methods • get – as part of URL • post – specified as XHTML form by the method “post” – sends form data as an HTTP message (not part of URL) • Retrieve and send client form data to Web server • Post data to a server-side form handler

  5. System Architecture • Multi-tier application (n-tier application) • Information tier (data or bottom tier) • Maintains data for the application • Stores data in a relational database management system (RDBMS) • Middle tier • Implements business logic and presentation logic • Control interactions between application clients and application data • Client tier (top tier) • Application’s user interface • Users interact directly with the application through the client tier

  6. Three-Tier Application Model Client Tier Application Middle Tier Database Information Tier

  7. Client-Side Scripting versus Server-Side Scripting • Client-side scripts • Validate user input • Reduce requests needed to be passed to server • Access browser • Enhance Web pages with DHTML, ActiveX controls, and applets • Server-side scripts • Executed on server • Generate custom response for clients • Wide range of programmatic capabilities • Access to server-side software that extends server functionality

  8. Accessing Web Servers • Request documents from Web servers • Host names • Local Web servers • Access through machine name or localhost • Remote Web servers • Access through machine name • Domain name or Internet Protocol (IP) address • Domain name server (DNS) • Computer that maintains a database of host names and their corresponding IP address

  9. Apache Web Server • Currently the most popular Web server • Stability • Efficiency • Portability • Open-source

  10. Apache Web Server Don’t count on it!

  11. Requesting Documents • Requesting two different documents • XHTML • PHP

  12. XHTML • Request XHTML documents from Apache • Launch Browser • Enter XHTML document’s location in Address field USE FACILITATOR GUIDE FOR INSTALLATION INSTRUCTIONS AND TUTORIAL!

  13. Web Resources • www.w3.org/Protocols • www.apache.org • httpd.apache.org • httpd.apache.org/docs-2.0 • www.apacheweek.com • linuxtoday.com/stories/18780.html

  14. LAMP • Linux, Apache, MySQL, and PHP • Linux provides the base operating system and server environment • Apache Web server intercepts HTTP requests and either serves them directly or passes them on to the PHP interpreter for execution • PHP interpreter parses and executes PHP code, and returns the results to the Web server • MySQL RDBMS serves as the data storage engine, accepting connections from the PHP layer and inserting, modifying, or retrieving data

  15. LAMP Development Framework http://my.server.com/webmail.php HTTP request HTTP response Web Browser Apache MySQL Windows OS PHP SQL query Result set Linux OS Joe Client Server

  16. LAMP • Joe pops open his Web browser at home and types in the URL for his online Webmail client. After looking up the domain, Joe’s browser (the client) sends an HTTP request to the corresponding server IP address • The Apache Web server handling HTTP requests for the domain receives the request and notes that the URL ends with a .php suffix. Because the server is programmed to automatically redirect all such requests to the PHP layer, it simply invokes the PHP interpreter and passes it the contents of the named file

  17. LAMP • The PHP interpreter parses the file, executing the code in the special PHP tags. If the code includes database queries, the PHP interpreter opens a client connection to the MySQL RDBMS and executes them. Once the script interpreter has completed executing the script, it returns the result to the browser, cleans up after itself, and goes back into hibernation • The results returned by the interpreter are transmitted to Joe’s browser by the Apache server

  18. PHP • Request PHP documents from Apache • Save PHP documents in the htdocs directory – use .php filenames • Launch Browser • Enter PHP document’s location in Address field

  19. PHP • PHP: Hypertext Preprocessor • Originally called “Personal Home Page Tools” • Popular server-side scripting technology • Open-source • Anyone may view, modify and redistribute source code • Supported freely by community • Platform independent

  20. PHP • Basic application • Scripting delimiters • <? php ?> • Must enclose all script code • Variables preceded by $ symbol • Case-sensitive • End statements with semicolon • Comments • // for single line • /* */ for multiline • Filenames end with .phpby convention

  21. Scripting delimiters Declare variable $name Single-line comment Function print outputs the value of variable $name PHP First Program Example

  22. PHP Output

  23. PHP Variables • Variables • Can have different types at different times • Variable names inside strings replaced by their value • Type conversions • settype function • Type casting • Concatenation operator • .(period) • Combine strings

  24. PHP Data Types

  25. Assign a string to variable $testString Assign a double to variable $testDouble Assign an integer to variable $testInteger PHP Data Types Example

  26. Call function settype to convert the data type of variable $testString to a double. Call function settype to convert the data type of variable $testString to an integer. Convert variable $testString back to a string Print each variable’s value

  27. Use type casting to cast variable $data to different types

  28. PHP Operators • Arithmetic operators • Assignment operators • Syntactical shortcuts • Before being assigned values, variables have value undef • Constants • Named values • define function

  29. Define constant VALUE. Add constant VALUE to variable $a. PHP Operators Example

  30. Multiply variable $a by two using the multiplication assignment operator *=. Test whether variable $a is less than 50 Print if variable $a is less than 50. Add 40 to variable $a using the addition assignment operator +=.

  31. Print an uninitialized variable ($nothing). Add constant VALUE to an uninitialized variable. Add a string to an integer.

  32. More PHP... • Keywords • Reserved for language features • if…elseif…else • Arrays • Group of related data • Elements • Name plus braces and index • Indices start at zero • count function • array function

  33. More PHP... • Arrays, cont. • Built-in iterators • Maintain pointer to element currently referenced • reset • key • next • foreach loops

  34. PHP Keywords

  35. Create the array $first by assigning a value to an array element. Use a for loop to print out each element’s index and value. Function count returns the total number of elements in the array. Assign a value to the array, omitting the index. Appends a new element to the end of the array. PHP Array Example

  36. Call function array to create an array that contains the arguments passed to it. Store the array in variable $second. Assign values to non-numerical indices in array $third. Function key returns the index of the element which the internal pointer references. Function reset sets the internal pointer to the first element of the array. Function next moves the internal pointer to the next element.

  37. Operator => is used in function array to assign each element a string index. The value to the left of the operator is the array index, and the value to the right is the element’s value.

  38. String Processing and Regular Expressions • String processing • Equality and comparison two important operations • strcmp function • Returns –1 if string 1 < string 2 • Returns 0 if string 1 = string 2 • Returns 1 if string 1 > string 2 • Relational operators

  39. Use a for loop to iterate through each array element. Function strcmp compares two strings. If the first string alphabetically precedes the second, then –1 is returned. If the strings are equal, 0 is returned. If the first string alphabetically follows the second, then 1 is returned. PHP String Comparision Example

  40. Use relational operators to compare each array element to string “apple”.

  41. String Processing and Regular Expressions • Regular expressions • Pattern matching templates • ereg function • POSIX • preg_match function • Perl • ereg_replace function • Building regular expressions • Metacharacters • $, ., ^ • Brackets [ ]

  42. Viewing Client/Server Environment Variables • Environment variables • Provide information about execution environment • Type of Web browser • Type of server • Details of HTTP connection • Stored as array in PHP • $_ENV

  43. Viewing Client/Server Environment Variables

  44. Form Processing and Business Logic • Form processing • action property • Where to send form data • method property • post • Each element has unique name

  45. The action attribute of the form element indicates that when the user clicks Register, the form data will be posted to form.php. PHP Using a Form Example

  46. A unique name (e.g., email) is assigned to each of the form’s input fields. When Register is clicked, each field’s name and value are sent to the Web server.

More Related