PHP - Hypertext Preprocessor. Introduction PHP is a powerful server-side scripting language for creating dynamic and interactive websites. PHP is a powerful.

Slides:



Advertisements
Similar presentations
IS 6116 Introduction – 10 Jan Lecturer Details Aonghus Sugrue Website: aonghussugrue.wordpress.com
Advertisements

SWU, Computer systems and technologies. The Objective of This Lecture To give you a very high-level overview of some of the tools for Web Programming.
1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)
WHAT IS PHP PHP is an HTML-embedded scripting language primarily used for dynamic Web applications.
PHP By Dr. Syed Noman Hasany. PHP PHP was originally created by Rasmus Lerdorf in PHP stands for PHP: Hypertext Preprocessor (a recursive acronym).
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 15: PHP Introduction.
Introduction to PHP. PHP PHP is the Hypertext Pre-processor –Script language –Embedded into HTML –Runs as Apache module –Can use DB (MySQL, Oracle, Microsoft.
CSC 318 WEB APPLICATION DEVELOPMENT.  Introduction to Server Scripting language  Client VS Server  Introduction to PHP  PHP Files and Syntax  Function.
1 Introduction to PHP. 2 What is this “PHP” thing? Official description: “PHP, which stands for "PHP: Hypertext Preprocessor" is a widely-used Open Source.
Programming with php By: Seth Larson. A little bit about PHP  PHP stands for PHP:  Hypertext Preprocessor  PHP is a widely-used general-purpose server-side.
PHP Tutorial By RAY BALIKI && ROY GHORAYEB. DEFINITION PHP is a powerful server-side scripting language for creating dynamic and interactive websites.
Mandakini Ayushi Infotech Mandakini Kumari 22 nd July PHP Basic.
SCV1223 PHP - Hypertext Preprocessor. Introduction PHP is a powerful server-side scripting language for creating dynamic and interactive websites. PHP.
Languages in WEB Presented by: Jenisha Kshatriya BCM SS09.
IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander.
INTERNET APPLICATION DEVELOPMENT For More visit:
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Nael Alian Introduction to PHP
PHP With Oracle 11g XE By Shyam Gurram Eastern Illinois University.
Week 9 PHP Cookies and Session Introduction to JavaScript.
10/5/2015CS346 PHP1 Module 1 Introduction to PHP.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Multifarious Project A personal -system Team Members Abdullah Alghamdi Metaib Alenzai Mohammed Alshehri Hamd Alshamsi.
Open Source Software Unit – 3 Presented By Mr. R.Aravindhan.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Web Programming Language Week 5 Dr. Ken Cosh Introducing PHP 1.
PHP. What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server.
Introduction to PHP Advanced Database System Lab no.1.
What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server PHP supports.
Introduction to Web Programming. Introduction to PHP What is PHP? What is a PHP File? What is MySQL? Why PHP? Where to Start?
Introduction to PHP.
IT ELECTIVE 2.  Web server Can refer to either the hardware (the computer) or the software (the computer application) that helps to deliver content that.
CHAPTER 6 Introduction to PHP5 Part I อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
PHP Introduction PHP is a server-side scripting language.
SESSIONS 27/2/12 Lecture 8. ? Operator Similar to the if statement but returns a value derived from one of two expressions by a colon. Syntax: (expression)
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 2: Introduction to IS2803 Rob Gleasure
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
 Before you continue you should have a basic understanding of the following:  HTML  CSS  JavaScript.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
PHP Syntax You cannot view the PHP source code by selecting "View source" in the browser - you will only see the output from the PHP file, which is plain.
Unit-6 Handling Sessions and Cookies. Concept of Session Session values are store in server side not in user’s machine. A session is available as long.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Web Page Designing With Dreamweaver MX\Session 1\1 of 9 Session 1 Introduction to PHP Hypertext Preprocessor - PHP.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
PHP-Basic By- Tanvi Raval. Pre-requisites Before you continue you should have a basic understanding of the following: 1. HTML 2. JavaScript.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
CGS 3066: Web Programming and Design Spring 2016 PHP.
PHP. What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server.
PHP stands for …….. “PHP Hypertext Pre-processor” and is a server-side scripting language like ASP. PHP scripts are executed on the server PHP supports.
PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used, free, and efficient alternative.
1 Server Side scripting PHP. 2 What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are.
Introduction to PHP. PHP Origins Rasmus LerdorfRasmus Lerdorf (born Greenland, ed Canada) PHP originally abbreviation for ‘Personal Home Pages’, now ‘PHP.
A pache M ySQL P hp Robert Mudge Reference:
PHP using MySQL Database for Web Development (part II)
CHAPTER 5 SERVER SIDE SCRIPTING
Introduction to Dynamic Web Programming
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
PHP Introduction.
PHP.
IntroductionToPHP Static vs. Dynamic websites
Intro to PHP.
Tutorial 6 PHP & MySQL Li Xu
Introduction to PHP.
PHP an introduction.
PHP By Prof. B.A.Khivsara Note: The material to prepare this presentation has been taken from internet and are generated only for students reference and.
Web Application Development Using PHP
Presentation transcript:

PHP - Hypertext Preprocessor

Introduction PHP is a powerful server-side scripting language for creating dynamic and interactive websites. PHP is a powerful server-side scripting language for creating dynamic and interactive websites. PHP is the widely-used, free, and efficient alternative to competitors such as Microsoft's ASP. PHP is the widely-used, free, and efficient alternative to competitors such as Microsoft's ASP. PHP is perfectly suited for Web development and can be embedded directly into the HTML code. PHP is perfectly suited for Web development and can be embedded directly into the HTML code. The PHP syntax is very similar to Perl and C. The PHP syntax is very similar to Perl and C. PHP is often used together with Apache (web server) on various operating systems. PHP is often used together with Apache (web server) on various operating systems. It also supports ISAPI and can be used with Microsoft's IIS on Windows. It also supports ISAPI and can be used with Microsoft's IIS on Windows.

What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP is a server-side scripting language, like ASP PHP scripts are executed on the server even though even though combined with an HTML code PHP scripts are executed on the server even though even though combined with an HTML code PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.) PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.) PHP is an open source software (OSS) PHP is an open source software (OSS) PHP is free to download and use PHP is free to download and use

What is a PHP File? PHP files may contain text, HTML tags and scripts PHP files may contain text, HTML tags and scripts PHP files are returned to the browser as plain HTML PHP files are returned to the browser as plain HTML PHP files have a file extension of ".php", ".php3", or ".phtml" PHP files have a file extension of ".php", ".php3", or ".phtml"

What is MySQL? MySQL is a database server MySQL is a database server MySQL is ideal for both small and large applications MySQL is ideal for both small and large applications MySQL supports standard SQL MySQL supports standard SQL MySQL compiles on a number of platforms MySQL compiles on a number of platforms MySQL is free to download and use MySQL is free to download and use

PHP + MySQL PHP combined with MySQL are cross-platform (means that you can develop in Windows and serve on a Unix platform) PHP combined with MySQL are cross-platform (means that you can develop in Windows and serve on a Unix platform)

Why PHP? PHP runs on different platforms (Windows, Linux, Unix, etc.) PHP runs on different platforms (Windows, Linux, Unix, etc.) PHP is compatible with almost all servers used today (Apache, IIS, etc.) PHP is compatible with almost all servers used today (Apache, IIS, etc.) PHP is FREE to download from the official PHP resource: PHP is FREE to download from the official PHP resource: PHP is easy to learn and runs efficiently on the server side PHP is easy to learn and runs efficiently on the server side

Where to Start? Install an Apache server on a Windows or Linux machine Install an Apache server on a Windows or Linux machine Install PHP on a Windows or Linux machine Install PHP on a Windows or Linux machine Install MySQL on a Windows or Linux machine Install MySQL on a Windows or Linux machine Install PHP triad Install PHP triad All in one All in one LAMP LAMP Linux Apache MySQL PHP Linux Apache MySQL PHP WAMP (Apache, PHP, MySQL) WAMP (Apache, PHP, MySQL) XAMPP (MySQL, PHP and Perl) XAMPP (MySQL, PHP and Perl)

First Example – Hello World! Activity 01 Activity 01 NOTES NOTES You cannot view the PHP source code by selecting "View source" in the browser You cannot view the PHP source code by selecting "View source" in the browser you will only see the output from the PHP file, which is plain HTML. you will only see the output from the PHP file, which is plain HTML. This is because the scripts are executed on the server before the result is sent back to the browser. This is because the scripts are executed on the server before the result is sent back to the browser.

PHP Syntax A PHP scripting block always starts with. A PHP scripting block always starts with. A PHP scripting block can be placed anywhere in the HTML document. A PHP scripting block can be placed anywhere in the HTML document. On servers with shorthand support enabled you can start a scripting block with. On servers with shorthand support enabled you can start a scripting block with. However, for maximum compatibility, it is recommend that you use the standard form (<?php) rather than the shorthand form. However, for maximum compatibility, it is recommend that you use the standard form (<?php) rather than the shorthand form.

PHP Syntax A PHP file normally contains HTML tags, just like an HTML file, and some PHP scripting code. A PHP file normally contains HTML tags, just like an HTML file, and some PHP scripting code. View source for activity 01 View source for activity 01 Each code line in PHP must end with a semicolon. Each code line in PHP must end with a semicolon. The semicolon is a separator and is used to distinguish one set of instructions from another. The semicolon is a separator and is used to distinguish one set of instructions from another. There are two basic statements to output text with PHP: echo and print. There are two basic statements to output text with PHP: echo and print. In activity 01, we have used the echo statement to output the text "Hello World". In activity 01, we have used the echo statement to output the text "Hello World".

PHP Syntax Comments in PHP Comments in PHP In PHP, we use // to make a single-line comment or In PHP, we use // to make a single-line comment or /* and */ to make a large comment block. /* and */ to make a large comment block.

PHP Variables All variables in PHP start with a $ sign symbol. All variables in PHP start with a $ sign symbol. Variables may contain strings, numbers, or arrays (untype). Variables may contain strings, numbers, or arrays (untype). Activity 02 Activity 02 Variable concatenation – using the (.) operator Variable concatenation – using the (.) operator All converted to string All converted to string Str. Str = str Str. Str = str Num. Num = str Num. Num = str

Variable Naming Rules Same as C, C++ or Java Same as C, C++ or Java A variable name must start with a letter or an underscore "_" A variable name must start with a letter or an underscore "_" A variable name can only contain alpha-numeric characters and underscores (a-Z, 0-9, and _ ) A variable name can only contain alpha-numeric characters and underscores (a-Z, 0-9, and _ ) A variable name should not contain spaces. A variable name should not contain spaces. If a variable name should be more than one word, it should be separated with underscore ($my_string), If a variable name should be more than one word, it should be separated with underscore ($my_string), or with capitalization ($myString) or with capitalization ($myString)

PHP operator, conditional Same as C or C++ Same as C or C++ PHP If...Else Statements – Activity 03 PHP If...Else Statements – Activity 03 Same as C or C++ Same as C or C++ Swith statement Swith statement Same as C or C++ Same as C or C++

PHP array (Numeric) Numeric Arrays ( Activity 04 ) Numeric Arrays ( Activity 04 ) $names = array("Peter","Quagmire","Joe"); $names = array("Peter","Quagmire","Joe"); Assign manualy: Assign manualy: $names[0] = "Peter"; $names[0] = "Peter"; $names[1] = "Quagmire"; $names[1] = "Quagmire"; $names[2] = "Joe"; $names[2] = "Joe";

PHP array (Associative) Using Hash technique ( Activity 04 ) Using Hash technique ( Activity 04 ) An associative array where each ID key is associated with a value. An associative array where each ID key is associated with a value. When storing data about specific named values, a numerical array is not always the best way to do it. When storing data about specific named values, a numerical array is not always the best way to do it. With associative arrays we can use the values as keys and assign values to them. With associative arrays we can use the values as keys and assign values to them.

PHP array (Associative) $ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34); $ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34); or or $ages['Peter'] = "32"; $ages['Peter'] = "32"; $ages['Quagmire'] = "30"; $ages['Quagmire'] = "30"; $ages['Joe'] = "34"; $ages['Joe'] = "34";

Tutorial 01 Download tutorial01.php Download tutorial01.php Produce out such as the following: Produce out such as the following: Father’s name: Quagmire Father’s name: Quagmire Children’s name: Glenn Children’s name: Glenn You need to upload your tutorial01.php to the server to view the result! You need to upload your tutorial01.php to the server to view the result!

PHP Looping – Activity 05 Same as C or C++ Same as C or C++ while - loops through a block of code if and as long as a specified condition is true while - loops through a block of code if and as long as a specified condition is true do...while - loops through a block of code once, and then repeats the loop as long as a special condition is true do...while - loops through a block of code once, and then repeats the loop as long as a special condition is true for - loops through a block of code a specified number of times for - loops through a block of code a specified number of times foreach - loops through a block of code for each element in an array foreach - loops through a block of code for each element in an array

PHP – Data transfer Transferring data between client (web browser) to the server-side Transferring data between client (web browser) to the server-side Two method: Two method: Using form: POST method Using form: POST method Through URL: GET method Through URL: GET method

POST Method  The body of the message is sent as a stream of data (HTML form data)  Separated with the PHP URL in the FORM post URL  Client send data to servlet using HTML form element

POST Method  Form tag <FORM METHOD=”post” ACTION=”login.php” ACTION=”login.php” TARGET=“”> TARGET=“”>  Fill the TARGET value if form result have to display in a different frame  After coding all the form element (button, textfield, etc) FORM tag must be close using the equivalent end tag -  After coding all the form element (button, textfield, etc) FORM tag must be close using the equivalent end tag -  If you have multiple form in a single page every separate every form using the end tag

GET method  The body of the message (the data) is appended to the PHP URL,   Separated by a question mark   Followed by name-value pair which separated by equals sign  If value consist of more than one word, separate it using plus sign which the php will convert it to space character after parsing  name=john+doe  Every consecutive name-value pair will be separated using ampersand sign (&)  name=john+doe&id=007

PHP Function  Also similar to C, C++ and Java  Normal – 8-1  With parameter – 8-2  Return value – 8-3

PHP object

PHP MySQL – Connect/Disconnect

PHP MySQL – mysql_query() mysql_query ( string $query [, resource $link_identifier] ) $query A SQL query The query string should not end with a semicolon. $link_identifier DB connection If is not specified, the last link opened by mysql_connect() is assumed otherwise DB error mysql_connect()

PHP MySQL – Create (Db & Table)

PHP MySQL – INSERT

PHP MySQL – SELECT

The example above stores the data returned by the mysql_query() function in the $result variable. Next, we use the mysql_fetch_array() function to return the first row from the recordset as an array. Each subsequent call to mysql_fetch_array() returns the next row in the recordset. The while loop loops through all the records in the recordset. To print the value of each row, we use the PHP $row variable ($row['FirstName'] and $row['LastName']).

PHP MySQL – SELECT WHERE clause WHERE clause

PHP MySQL – SELECT ORDER by – record sorting ORDER by – record sorting

PHP MySQL – UPDATE

PHP MySQL – DELETE

PHP Session A PHP session allow us to store user information on the server for later use (i.e. username, shopping items, etc). A PHP session allow us to store user information on the server for later use (i.e. username, shopping items, etc). However, session information is temporary and will be deleted after the user has left the website. However, session information is temporary and will be deleted after the user has left the website. If you need a permanent storage you may want to store the data in a database. If you need a permanent storage you may want to store the data in a database. Sessions work by creating a unique id (UID) for each visitor and store variables based on this UID. Sessions work by creating a unique id (UID) for each visitor and store variables based on this UID. The UID is either stored in a cookie or is propagated in the URL. The UID is either stored in a cookie or is propagated in the URL.

PHP Cookies A cookies allow us to store user information permanently on the user’s machine (client) for later use (i.e. username & password, last visit etc). A cookies allow us to store user information permanently on the user’s machine (client) for later use (i.e. username & password, last visit etc). arguments are setcookie(name, value, expiration): arguments are setcookie(name, value, expiration):

PHP Cookies A cookies allow us to store user information permanently on the user’s machine (client) for later use (i.e. username & password, last visit etc). A cookies allow us to store user information permanently on the user’s machine (client) for later use (i.e. username & password, last visit etc). arguments are setcookie(name, value, expiration): arguments are setcookie(name, value, expiration):

PHP Cookies name: The name of your cookie. You will use this name to later retrieve your cookie, so don't forget it! name: The name of your cookie. You will use this name to later retrieve your cookie, so don't forget it! value: The value that is stored in your cookie. Common values are username(string) and last visit(date). value: The value that is stored in your cookie. Common values are username(string) and last visit(date). expiration: The date when the cookie will expire and be deleted. If you do not set this expiration date, then it will be treated as a session cookie and be removed when the browser is restarted. expiration: The date when the cookie will expire and be deleted. If you do not set this expiration date, then it will be treated as a session cookie and be removed when the browser is restarted. setcookie("user", “kim bo-ra", time()+3600); setcookie("user", “kim bo-ra", time()+3600); Expire in 1 hour Expire in 1 hour

PHP Cookies Last visit: Last visit: //Calculate 60 days in the future //Calculate 60 days in the future //seconds * minutes * hours * days + current time //seconds * minutes * hours * days + current time $inTwoMonths = 60 * 60 * 24 * 60 + time(); $inTwoMonths = 60 * 60 * 24 * 60 + time(); setcookie(lastVisit, date("G:i - m/d/y“, $inTwoMonths) setcookie(lastVisit, date("G:i - m/d/y“, $inTwoMonths) Deleting cookies: Deleting cookies: When deleting a cookie you should assure that the expiration date is in the past. When deleting a cookie you should assure that the expiration date is in the past. setcookie("user", "", time()-3600); setcookie("user", "", time()-3600);

PHP Session Starting session: Starting session: session_start(); session_start(); No session exist – new session variable created, No session exist – new session variable created, otherwise, current session variable is retrieve otherwise, current session variable is retrieve Storing data in session ($_SESSION) Storing data in session ($_SESSION) $_SESSION['views']=1; $_SESSION['views']=1; Retrieving and checking Retrieving and checking echo "Pageviews=". $_SESSION['views']; echo "Pageviews=". $_SESSION['views']; isset($_SESSION['user']) – checking if variable user exist in $_SESSION isset($_SESSION['user']) – checking if variable user exist in $_SESSION Destroying session data and session Destroying session data and session Session data: unset($_SESSION['views']); Session data: unset($_SESSION['views']); session_destroy(); session_destroy();

Authenticating, Access Control & Profile Management  Using FORM authentication  Supplying login and password through HTML Form to log to the restricted application  Data send to php script using SSL protocol – prevent from sniffer  PHP for login-password processing and PHP redirecting  Authenticating user login and password from the database  Creating user session  Creating user profile using User Object and store in the user newly created session  Direct user to the session protected PHP pages

Authenticating, Access Control & Profile Management  PHP pages (view)  Control user access to protected resources using user session  Every PHP pages which involve in the restricted application should also have a section for session authentication