Download presentation
Presentation is loading. Please wait.
Published byMarlene Parker Modified over 9 years ago
1
CSC 318 WEB APPLICATION DEVELOPMENT
2
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
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.
5
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
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
7
Faster to display since workload is distributed to user’s PC Customizable output – personalized experience Cannot retain global data Cannot store data from user into database
8
Data from user can be stored into database Web server control user’s browsing selection The processing is centralized at the server. This will put the burden of processing on the server instead of the client
9
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 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.
11
PHP can restrict users to access some pages on your website PHP 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 dataPHP 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.
13
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
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 PHP Module Web Server (XAMPP) Send script Return output
15
Install a web server – Eg. XAMPP Install PHP – Eg. phpMyAdmin Install a database, such as MySQL
16
Install PHP MyAdmin – for database & coding platform http://www.phpmyadmin.net/home_page/index.php 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 http://www.wikihow.com/Install-XAMPP-for-Windows
17
client server URL request HTML PHP Script request HTML
18
PHP code is surrounded with by delimeter <? is open section for PHP ?> is closing section of PHP
19
PHP code skeleton: … First style Second style Third style
21
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 spaces - blank lines, tabs and extra spaces To alter spacing of finished web page, use ▪ - line break ▪ - 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
23
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
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
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
Valid number-type variables can be 8 3.14 1098727272798 -4.2828282 Arithmetic operators + addition - subtraction * multiplication / division % modular ++ increment -- decrement
27
Functions round() ▪ $j = 3.14; ▪ $k = round( $j); number_format() ▪ $p =20980; ▪ $g=number_format($p); ▪ $g=number_format($p,2);
28
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 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
“” 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
32
Setup Creating an HTML form Handling an HTML form
33
Client Web-browser Client Web-browser Server Apache Server Server Apache Server URL request HTML PHP Script request HTML 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
34
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.
35
Step 1: create html form Step 2: create php scripts that receive form data
36
how data is sent (get or post) which page the form data will be send
38
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 “ Thank you, {$_POST[‘age’]} for the following comments”; Age: attributes
39
http://www.homeandlearn.co.uk/php/php.html http://www.homeandlearn.co.uk/php/php.html http://www.php.net http://www.php.net http://www.w3schools.com/php/ http://www.w3schools.com/php/ http://devzone.zend.com/6/ http://devzone.zend.com/6/ http://www.webmonkey.com/2010/02/php_tutorial_for_beginners/ http://www.webmonkey.com/2010/02/php_tutorial_for_beginners/
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.