IT Engineering I Instructor: Rezvan Shiravi [email protected] 1.

93
PHP IT Engineering I Instructor: Rezvan Shiravi [email protected] 1

Transcript of IT Engineering I Instructor: Rezvan Shiravi [email protected] 1.

  • Slide 1
  • IT Engineering I Instructor: Rezvan Shiravi [email protected] 1
  • Slide 2
  • Questions Q1) How does server process clients requests? Q2) How to code in server side? Q3) Which language? Syntax? Q4) How can I get valid users data in server? Q5) Can I read/write access to HTTP headers Q6) The users must login to access the site! Q7) Can I use data base? How? 2
  • Slide 3
  • Introduction HTML/XHTML content is static JavaScript & Ajax make pages more dynamic, but the content is almost static Dynamic content Pages that look differently depending on the user who visits, status, processing requests, Web applications (hotel booking, web search applications, ) is not possible using only HTML/XHTML, CSS and JS, why? We need server side active code Perform actions & generate (dynamic) content 3
  • Slide 4
  • Common Gateway Interface We need code beside web servers Web servers by itself are not designed for data processing Standard protocol for interfacing external application software with the web server CGI 1.1 specified in RFC 3875, 2004 Defines how information is passed from the web server to the executable program Defines how information is passed from external software to the web server allows an external executable file to respond to an HTTP Request from the browser 4
  • Slide 5
  • Embed vs. External Server Side Code External code Separated program: C, C++ Server runs it and sends its output back to client The program needs to generate whole HTML page Embed code Scripting inside the HTML Embed programming interface within server Which is called when server see the scripting directions We dont need to generated HTML by script Examples Perl: Apache mod_perl module to embed Java Server Pages (JSP): Compiled and served by a JSP server Active Server Pages (ASP): Microsoft IIS PHP 5
  • Slide 6
  • Overview of Server-Side Scripting 6
  • Slide 7
  • 1) Web client sends a HTTP request to server 2) Web server determines how to retrieve the requested resource according configuration.php : To be handled by the PHP module.html,.jpg,... To be retrieve directly 3) Runtime environment Parses incoming request, generate outgoing response Interpreting/executing the server-side scripts Maintaining sessions 7
  • Slide 8
  • Overview of Server-Side Scripting 4) Runtime environment runs the requested script Provide session & other status information Generated output is the body of a HTTP response 5) The HTTP response is sent to the web client 8
  • Slide 9
  • PHP Introduction PHP stands for Originally Personal Home Pages PHP: Hypertext Preprocessor Widely-used scripting language Especially suited for Web development Server side scripting :Dynamic Content Typically runs on a web server that takes PHP as input and gives out HTML pages as output 9
  • Slide 10
  • PHP Features Open source & free A syntax similar to C and Java Connects with 20+ databases Version 5+ supports OOP Multi-platform compatible Linux & Windows & Wide range of web servers Rich library: Over 700 built-in functions Easy to learn but hard to master 10
  • Slide 11
  • PHP Scripts Typically file ends in.php PHP scripts run when user wants to GET/POST them PHP commands can make up an entire file, or can be contained in html Server recognizes embedded script and executes Separated in files with the tag Or tag Can be placed anywhere in the document Result passed to browser, source isn't visible 11
  • Slide 12
  • PHP in Action Installation From source: Apache: http://httpd.apache.org/ PHP: http://www.php.net MySQL: http://www.mysql.y p yql.com/ 12
  • Slide 13