Web Programming Introduction to PHP COM427 1. Objectives To understand what PHP is and how a PHP script works with a Web Browser and a Web Server To learn.

Download Web Programming Introduction to PHP COM427 1. Objectives To understand what PHP is and how a PHP script works with a Web Browser and a Web Server To learn.

Post on 23-Dec-2015

214 views

Category:

Documents

0 download

TRANSCRIPT

  • Slide 1
  • Web Programming Introduction to PHP COM427 1
  • Slide 2
  • Objectives To understand what PHP is and how a PHP script works with a Web Browser and a Web Server To learn what software and components you need to get started with PHP To create and run a simple PHP script COM427 2
  • Slide 3
  • Web servers Can be considered at two levels: 1.The physical computer that stores web files and web application programs. 2.More precisely, the web server is a specialized piece of software, running on the server computer, which receives requests, via the Internet, for web pages or programs retrieves the pages / executes the programs returns the results over the Internet to the browser. Common web servers: Apache Microsoft Internet Information Services (IIS) COM427 3
  • Slide 4
  • Web Application Program Carries out many dynamic tasks, such as the following: Input a search term, search the WWW, and return the results Calculate and display the number of times that a page has been viewed Verify the input fields on a Web form Save a Web form into a database Display a special graph, or return the results of a calculation based on data input from a form COM427 4
  • Slide 5
  • What is PHP? Original of PHP (Rasmus Lerdorf) [born in Qeqertarsuaq, Greenland] Server side e.g. form handling, database access (as opposed to Javascript which is mainly clientside) (X)HTML-embedded scripting language COM427 5
  • Slide 6
  • Basic Browser Web Server interaction 6 1. Browser in Client sents http request e.g. http://localhost/~labuser/test.php 2. Server receives request and activates php to interpret php program (test.php) 3. Server sends html output to browser in client for display
  • Slide 7
  • PHP Advantages Advantages of Using PHP to enhance Web pages: Easy to use. Open source. Multiple platform. COM427 7
  • Slide 8
  • Browser PHP MySQL Interaction 8 A third layer can be added if php makes a call to a database to supply data in response to web browser request
  • Slide 9
  • Browser/PHP/database example 9 Browser holds html form Enter Details of Car Reg Num Make Submit PHP program - Receives values - Plugs them into database query - Sends Request to database - Receives data and - Returns result as web page Details of Car Taxed ? Yes MOT? Yes Reg Date: 1 st Jan 2010 https://www.gov.uk/check-vehicle-tax Car Database
  • Slide 10
  • PHP & Javascript Javascript Client side Good for form validation Good for web page presentation Poor for security Some database access PHP Server side Better security Good database access COM42710
  • Slide 11
  • Getting Started with PHP To develop and publish PHP scripts all you need is: A Web server with PHP built into it A client machine with a basic text editor and Internet connection FTP software (if webserver used) Use localhost in the development phase and then upload to the server COM427 11
  • Slide 12
  • Installation of Apache, PHP and MySQL In the lab: Apache server, PHP, MySQL installed At home: Install Apache, PHP and MySQL separately, Or install Apache, PHP, MySQL together using a package, eg. WAMP or MAMP (for Windows or Mac) XAMPP installs very easily & is cross-platform (Windows or Mac) COM427 12
  • Slide 13
  • Install Apache, PHP & MySQL Download XAMPP http://sourceforge.net/projects/xampp Installs Apache/PHP/MySQL (plus PERL) Cross platform (Mac/Windows/Linux) COM427 13
  • Slide 14
  • Using Apache, PHP and MySQL iMAC Lab Save your HTML file (e.g. test.html) or PHP file (e.g. myprog.php) under: Macintosh ID/Users/Labuser/Sites Run html or php file under Apache using: e.g. http://localhost/~labuser/test.html OR create subdirectory starting with b (e.g. student number b00XXXXXX ) http://localhost/~labuser/b00XXXXXX Click on file in browser window Windows Lab/ Own Windows Machine [ Put files in C://xampp/htdocs e.g. hello.php URL to run file http://localhost/hello.php OR create subdirectory and click on browser list] COM427 14
  • Slide 15
  • Using MySQL http://localhost/phpMyAdmin MAC Lab Login (MySQL) Login: labuser Password: macimd15 Windows Lab login (MySQL) Login: labuser Password: Labuser1 COM42715
  • Slide 16
  • Creating a PHP Script File You can use a number of different editors to create your PHP script files. TextWrangler (can add line numbers) Save file with.php extension [In Windows Lab can use Notepad++ to create PHP scripts] COM427 16
  • Slide 17

Recommended

View more >