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




0 download

Embed Size (px)


<ul><li> Slide 1 </li> <li> Web Programming Introduction to PHP COM427 1 </li> <li> Slide 2 </li> <li> 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 </li> <li> Slide 3 </li> <li> 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 </li> <li> Slide 4 </li> <li> 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 </li> <li> Slide 5 </li> <li> 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 </li> <li> Slide 6 </li> <li> 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 </li> <li> Slide 7 </li> <li> PHP Advantages Advantages of Using PHP to enhance Web pages: Easy to use. Open source. Multiple platform. COM427 7 </li> <li> Slide 8 </li> <li> 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 </li> <li> Slide 9 </li> <li> 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 </li> <li> Slide 10 </li> <li> PHP &amp; 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 </li> <li> Slide 11 </li> <li> 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 </li> <li> Slide 12 </li> <li> 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 &amp; is cross-platform (Windows or Mac) COM427 12 </li> <li> Slide 13 </li> <li> Install Apache, PHP &amp; MySQL Download XAMPP http://sourceforge.net/projects/xampp Installs Apache/PHP/MySQL (plus PERL) Cross platform (Mac/Windows/Linux) COM427 13 </li> <li> Slide 14 </li> <li> 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 </li> <li> Slide 15 </li> <li> Using MySQL http://localhost/phpMyAdmin MAC Lab Login (MySQL) Login: labuser Password: macimd15 Windows Lab login (MySQL) Login: labuser Password: Labuser1 COM42715 </li> <li> Slide 16 </li> <li> 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 </li> <li> Slide 17 </li> </ul>


View more >