1 / 39

Introduction to PHP

CSC 318 WEB APPLICATION DEVELOPMENT. Introduction to PHP. Overview. Introduction to Server Scripting language Client VS Server Introduction to PHP PHP Files and Syntax Function of PHP Why PHP? Implementing PHP How PHPWorks ? Requirements for PHP How to write PHP codes.

tam
Download Presentation

Introduction to PHP

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. CSC 318 WEB APPLICATION DEVELOPMENT Introduction to PHP

  2. Overview • Introduction to Server Scripting language • Client VS Server • Introduction to PHP • PHP Files and Syntax • Function of PHP • Why PHP? • Implementing PHP • How PHPWorks? • Requirements for PHP • How to write PHP codes

  3. Learning Outcome • Students will design and develop webpage using Server-Side scripting for efficient user interaction. • Students will establish, configure and maintain an intranet and internet website. • Students will understand about PHP, requirement and function of PHP.

  4. Introduction Client Server Communication • What is server? • A (software program | computer) that provides a specific kind of service to client software running on the same computer or other (clients | computers) on a network • Example: • Web server, file server, DHCP server • What is client? • A (computer | program | process) that makes requests for information from another (computer | program | process) in a client-server relationship

  5. Introduction to Scripting • In a client-server application there are two kinds of scripts or program: • client-side script client side script like Client-JavaScript is run on the client computer using web browser. • server-side script server-side script like ASP,PHP, and ColdFusion is run by Web server (such as IIS Apache, etc.)

  6. Client Vs Server Client-side scripts Server-side scripts

  7. Client Side Processing Advantages Disadvantages Cannot retain global data Cannot store data from user into database • Faster to display since workload is distributed to user’s PC • Customizable output – personalized experience

  8. Server Side Processing Advantages Disadvantages The processing is centralized at the server. This will put the burden of processing on the server instead of the client • Data from user can be stored into database • Web server control user’s browsing selection

  9. Introduction to PHP • PHP • To have basic understanding of HTML, CSS and JavaScript • PHP stands for “Hypertext Preprocessor“ • PHP is a widely-used, open source scripting language • PHP scripts are executed on the server • PHP is open source software and it is FREE • Current version of PHP is Version 6.

  10. PHP File & Syntax • PHP files can contain text, HTML, CSS, JavaScript, and PHP code • PHP code are executed on the server, and the result is returned to the browser as plain HTML • PHP files have extension “*.php“ • In terms of keywords and language syntax, PHP is similar to most high level languages that follow the C style syntax.  • ifconditions, for and while loops, and function returns are similar in syntax to languages such as C, C++, C#, Java and Perl.

  11. Function of PHP

  12. Why PHP • PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.) • PHP is compatible with almost all servers used today (Apache, IIS, etc.) • PHP supports a wide range of databases • Download material of PHP from the official PHP resource: www.php.net

  13. Implementing PHP • To implement PHP, you need a SERVER inside your computer – It is FREE! • Server is used to test PHP script in your computer. • PHP code is interpreted by a web server with a PHP processor module, which generates the resulting web page. • PHP commands can be embedded directly into an HTML source document rather than calling an external file to process data

  14. How PHP Works Send script PHP Scripts Return output Web browser Web Server (XAMPP) • PHP code is interpreted by a web server with a PHP processor module, which generates the resulting web page: PHP commands can be embedded directly into an HTML source document rather than calling an external file to process data. PHP Module

  15. Requirement for PHP • Install a web server – Eg. XAMPP • Install PHP – Eg. phpMyAdmin • Install a database, such as MySQL

  16. Requirement for PHP • Install PHP MyAdmin – for database & coding platform • http://www.phpmyadmin.net/home_page/index.php • Look & try at the “Demo” first before download the software. • Install XAMPP – for server • http://www.wikihow.com/Install-XAMPP-for-Windows

  17. PHP URL request server client HTML Script request HTML PHP

  18. How to write your PHP • PHP code is surrounded with by delimeter • <? … ?> • <? is open section for PHP • ?> is closing section of PHP

  19. PHP Block PHP code skeleton: <?php …. ?> Firststyle <? … ?> Second style <script language = “PHP”> … </script> Thirdstyle

  20. PHP Programming Style

  21. Sending data to web browser • Use PHP built in functions • Example • echo ‘Hello Student’; • print “ How are you”; • Case-insensitive for function names • ECHO, echo, Echo • Other print functions • print_r, var_dump - value of variable • print_f - formatting what you print

  22. White space, HTML and PHP • White spaces - blank lines, tabs and extra spaces • To alter spacing of finished web page, use • <br /> - line break • <p></p> - paragraph • To alter spacing of HTML source from PHP, use • echo() orprint() over the course of several lines • \n (newline character)within double quotation marks

  23. Writing comments • Important aspect to dynamic web site development • Viewable in the source but not in the browser window • PHP supports 3 type of comments • # this is a comment • //this is also a comment • /*this is a larger comment that spans two line */

  24. Variables • Rules of thumb • Variable name must start with dollar sign ($) • Combination of strings, numbers and the underscore • First character after dollar sign cannot be a number • Case sensitive • Assigned value using equals sign (=)

  25. String • A quoted chunk of letters, numbers, spaces, punctuation .. • Example strings • ‘hello’ • ‘software’ • ‘1000’ • ’12 January, 2006’ • String variable – assign a string value to valid variable name • $today =’16 July, 2007’; • To print out • echo $today; • echo “Today is $today”; • Concatenation string • Addition of strings using period (.). • $day=‘12’; • $month=‘January’; • $year =‘2006’; • $today = $day . ’ ‘ . $month . ’ ‘ . $year; • Use it extensively when building database queries in later chapters

  26. Numbers • Valid number-type variables can be • 8 • 3.14 • 1098727272798 • -4.2828282 • Arithmetic operators • + addition • - subtraction • * multiplication • /division • % modular • ++increment • -- decrement

  27. Numbers • Functions • round() • $j = 3.14; • $k = round( $j); • number_format() • $p =20980; • $g=number_format($p); • $g=number_format($p,2);

  28. Constant • Specific data type • Retain initial value throughout script • Cannot change once it has been set • Use define() • define (‘AGE’, ‘value’); • Print constant • echo ‘Hello, ‘ . AGE; OR • echo ‘Hello,’, AGE;

  29. Single vs Double Quotation Marks • Single quote -> values treated literally • Double quote -> interpolated • Example: • $var =‘Hello’; • echo “var equal to $var”; • var equal to hello • echo ‘var equal to $var’; • var equal to $var • echo “\$var is equal to $var”; • $var is equal to hello

  30. Single vs Double quotation marks • “” • replace variables name with its value and a special character’s code (\$) with its represented value • ‘’ • display exactly what you type, except for the escaped single quote (\’) and the escape backslash(\\).

  31. PROGRAMMING WITH PHP PROGRAMMING WITH PHP

  32. Discuss on.. • Setup • Creating an HTML form • Handling an HTML form

  33. Setup To open the electronic page localhost/foldername/pagename.extension Server and Database xampp [ Apache:web server , MySQL: database] Programming Languages HTML:design , JavaScript:Validation PHP:Server Side Scripting , SQL: Data manipulation Folder and Electronic Page Save the electronic page in a folder Save the folder : xampp/htdocs URL request Server Apache Server Client Web-browser HTML HTML Script request PHP

  34. HTML form • Managing HTML form with PHP involves 2 steps : • Step 1: Create HTML formwith any text editor • HTML form (.htm/.html) is created using the HTML form tags and various input types. • Step 2: Create PHP scriptsthat receives form data • PHP script (.php) is created to receives the submitted form data and handle it.

  35. Handling HTML form Step 1: create html form Step 2: create php scripts that receive form data

  36. Step 1: create html form form.html which page the form data will be send how data is sent (get or post)

  37. Step 2: create php script procesform.php

  38. Superglobalvariable • If you have a text box in html form with name attribute age, PHP will store the text entered there in a variable called$age (registered global variable) • $age is similar to $_POST[‘age’] (superglobal variables) • eg : ( in HTML form) • eg : ( in PHP scripts) echo “<p>Thank you, {$_POST[‘age’]} for the following comments”; attributes <p><b>Age: </b><input type ="text" name=“age" size="20" maxlength="40"/></p>

  39. References • http://www.homeandlearn.co.uk/php/php.html • http://www.php.net • http://www.w3schools.com/php/ • http://devzone.zend.com/6/ • http://www.webmonkey.com/2010/02/php_tutorial_for_beginners/

More Related