Upload
tam
View
47
Download
0
Tags:
Embed Size (px)
DESCRIPTION
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. - PowerPoint PPT Presentation
Citation preview
Introduction to PHPCSC 318WEB APPLICATION DEVELOPMENT
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
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.
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
`
Client-side Server-side
Send request to the server
Return file to the client
Send another request to the server
Return required file to the client
Introduction to Scripting
In a client-server application there are two kinds of scripts or program:
client-side scriptclient side script like Client-JavaScript is run on the client computer using web browser.
server-side scriptserver-side script like ASP,PHP, and ColdFusion is run by Web server (such as IIS Apache, etc.)
Client Vs Server
•Reduce requests needed to be passed to server•Access browser•Enhance Web pages with DHTML, ActiveX controls, and applets
•Validate user input•Executed on server•Generate custom response for client•Wide range of programmatic capabilities•Access to server-side software that extends server functionality
Server-side scripts
Client-side scripts
Client Side Processing
Advantages
Faster to display since workload is distributed to user’s PC
Customizable output – personalized experience
Disadvantages
Cannot retain global data
Cannot store data from user into database
Server Side Processing
Advantages
Data from user can be stored into database
Web server control user’s browsing selection
Disadvantages
The processing is centralized at the server. This will put the burden of processing on the server instead of the client
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.
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.
if conditions, for and while loops, and function returns are similar in syntax to languages such as C, C++, C#, Java and Perl.
Function of PHP
PHP can restrict users to access some pages
on your websitePHP can add, delete, modify data in your
database
PHP can create, open, read, write, and close
files on the server
PHP can generate dynamic page content PHP collect form data PHP can encrypt data
PHP can send and receive cookies
With PHP you are not limited to output
HTML. You can output images, PDF files, and even Flash movies. You
can also output any text, such as XHTML
and XML.
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
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
How PHP Works
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 Scripts
Web browser
PHPModule
Web Server (XAMPP)
Send script
Return output
Requirement for PHP
Install a web server – Eg. XAMPP Install PHP – Eg. phpMyAdmin Install a database, such as MySQL
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
PHP
client serverURL request
HTML
PHP
Script requestHTML
How to write your PHP
PHP code is surrounded with by delimeter <? … ?> <? is open section for PHP ?> is closing section of PHP
PHP code skeleton:
PHP Block
<?php …. ?>
<? … ?>
<script language = “PHP”> … </script>
First style
Second style
Third style
PHP Programming Style
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
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() or print() over the course of several lines ▪ \n (newline character) within double quotation marks
White space, HTML and PHP
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 */
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 (=)
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
Numbers
Valid number-type variables can be 8 3.14 1098727272798 -4.2828282
Arithmetic operators + addition - subtraction * multiplication / division % modular ++ increment -- decrement
Numbers
Functions round()
▪ $j = 3.14;▪ $k = round( $j);
number_format()▪ $p =20980;▪ $g=number_format($p);▪ $g=number_format($p,2);
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;
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
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(\\).
Single vs Double quotation marks
PROGRAMMING WITH PHP
PROGRAMMING WITH PHP
Discuss on..
Setup Creating an HTML form Handling an HTML form
Setup
ClientWeb-browser
ServerApache Server
URL request
HTML
PHP
Script requestHTMLTo open the electronic
pagelocalhost/foldername/pagename.extension
Server and Databasexampp [ Apache:web server , MySQL: database]
Programming LanguagesHTML:design , JavaScript:Validation
PHP:Server Side Scripting , SQL: Data manipulation
Folder and Electronic Page
Save the electronic page in a folderSave the folder : xampp/htdocs
Managing HTML form with PHP involves 2 steps :
1.Step 1:Create HTML form with any text editor• HTML form (.htm/.html) is created using the HTML
form tags and various input types.
2. Step 2:Create PHP scripts that receives form data• PHP script (.php) is created to receives the submitted
form data and handle it.
HTML form
Handling HTML form Step 1: create html form
Step 2: create php scripts that receive form data
Step 1: create html form form.html
how data is sent(get or post)
which page the form data will be send
Step 2: create php script procesform.php
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”;
Superglobal variable
<p><b>Age: </b><input type ="text" name=“age" size="20" maxlength="40"/></p>
attributes
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/