BMC3183 Advance Web Programming Programming Session 2013/2014.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

Introducing JavaScript
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
The Web Warrior Guide to Web Design Technologies
PHP Programming with MySQL Slide 2-1 CHAPTER 2 Getting Started with PHP.
Objectives Install and configure a Web server
PHP Introduction.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Tutorial 10 Programming with JavaScript
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Introduction to PHP (Part-1) Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
ASP.NET Programming with C# and SQL Server First Edition
JavaScript, Third Edition
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)
8/17/2015CS346 PHP1 Module 1 Introduction to PHP.
Lecture 2 Introduction to PHP MIS 3501, Spring 2014 Jeremy Shafer Department of MIS Fox School of Business Temple University January 30, 2014.
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.
LEARN THE QUICK AND EASY WAY! VISUAL QUICKPRO GUIDE Chapter 1: Introduction Dr. Mogeeb Moslehh Date: 15 March 2014 Saturday ( pm) SE3 Lecture Room:
Copyright © Curt Hill PhP History and Introduction.
Chapter 4 – The Building Blocks Data Types Literals Variables Constants.
ITD 3194 Web Application Development Chapter 4: Web Programming Language.
AIT 616 Fall 2002 PHP. AIT 616 Fall 2002 PHP  Special scripting language used to dynamically generate web documents  Open source – Free!!!  Performs.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
INTERNET APPLICATION DEVELOPMENT For More visit:
PHP TUTORIAL. HISTORY OF PHP  PHP as it's known today is actually the successor to a product named PHP/FI.  Created in 1994 by Rasmus Lerdorf, the very.
Writing Web Pages By Shyam Gurram. Agenda Writing Web Pages Delimiting PHP Program Units. Displaying Output to Web Pages Putting Comments in PHP Programs.
10/5/2015CS346 PHP1 Module 1 Introduction to PHP.
1 JavaScript in Context. Server-Side Programming.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
1 Working with Data Types and Operators. 2 Using Variables and Constants The values stored in computer memory are called variables The values, or data,
Introduction to PHP “PHP is a server-side scripting language designed specifically for the Web. Within an HTML page, you can embed PHP code that will be.
Introduction to PHP A user navigates in her browser to a page that ends with a.php extension The request is sent to a web server, which directs the request.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
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.
ITM © Port, KazmanVariables - 1 ITM 352 Data types, Variables.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
©John Samuel 2008 Introduction to PHP. ©John Samuel 2008 Objectives At the end of this class the student will be able to; Create and run a simple php.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Creating PHP Pages Chapter 6 PHP Variables, Constants and Operators.
1 JavaScript in Context. Server-Side Programming.
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 Programming with MySQL Slide 3-1 CHAPTER 3 Working with Data Types and Operators.
Creating PHP Pages Chapter 5 PHP Structure and Syntax.
©John Samuel 2008 Introduction to PHP Note: These slides are not included in coverage for the BIF703 final exam...
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
ITM © Port, KazmanVariables - 1 ITM 352 Data types, Variables Class #4.
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,
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
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.
Introduction to PHP. PHP Origins Rasmus LerdorfRasmus Lerdorf (born Greenland, ed Canada) PHP originally abbreviation for ‘Personal Home Pages’, now ‘PHP.
PHP using MySQL Database for Web Development (part II)
Objectives In this chapter you will: Create PHP scripts
PHP Introduction.
Chapter 2 Getting Started with PHP PHP Programming with MySQL
WEB PROGRAMMING JavaScript.
PHP.
Objectives Install and configure a Web server
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Intro to PHP.
23 PHP.
Presentation transcript:

BMC3183 Advance Web Programming Programming Session 2013/2014

2 Outlines History Why php Php overview Install and configure a Web server Install and configure PHP Install and configure MySQL Create basic PHP scripts and PHP code blocks Variables and constants Data types Expressions and operators

History Started as a Perl hack in 1994 by Rasmus Lerdorf (to handle his resume), developed to PHP/FI 2.0 By 1997 up to PHP 3.0 with a new parser engine by Zeev Suraski and Andi Gutmans Version is current version, rewritten by Zend ( to include a number of features, such as an object model Current is version 5 php is one of the premier examples of what an open source project can be

Why php?..there are no. of server side scripting available like ASP, SSJS, JSP….. PHP involves simplicity in scripting (..generally using the database) platform independence. PHP is primarily designed for web applications well optimized for the response times needed for web applications Is an open source.

5 PHP Overview PHP Hypertext Preprocessor. Other Names : Personal Home Page, Professional Home Page PHP is a server-side scripting language whose scripts are embedded in HTML documents Is a server side scripting language. Capable of generating the HTML pages HTML generates the web page with the static text and images. However the need evolved for dynamic web based application, mostly involving database usage.

6 Installing Software Install a Web server Install PHP Install MySQL Portable WAMP server NetBeans IDE: Quickly and easily develop desktop, mobile and web applications with Java, HTML5, PHP, C/C++ and more

Installation Options XAMPP: is a very easy to install package for (Linux- Windows- Apple). Apache, MySQL, PHP, Perl, and many more. WampServer will install Apache, PHP5 and MySQL on your Windows. ZendFramework: - the most popular framework for modern, high performance php application. ( Modular - Extensible High Performing - Secure 7

ZendFramework the most popular framework for modern, high performance php application. ( Modular - Extensible High Performing - Secure Zend provides Zend engine for PHP for free They provide other products and services for a fee Server side caching and other optimizations Encoding in Zend's intermediate format to protect source code IDE-a developer's package with tools to make life easier Zend's web site is a great resource

PHP 5 Architecture Zend engine as parser (Andi Gutmans and Zeev Suraski) SAPI is a web server abstraction layer PHP components now self contained (ODBC, Java, LDAP, etc.) This structure is a good general design for software (compare to OSI model, and middleware applications) image from

10 Understanding Binary and Source Code Installations Binary format (or binaries) refer to compiled files, such as executable installation programs Source code is the original programming code in which an application was written Source code must be compiled, or processed, and assembled into an executable format before it is used Compiled programs only need to be recompiled when their code changes

11 Installing and Configuring a Web Server Apache is the most popular Web server software used on the Internet Microsoft IIS for Windows is the second most popular server software In Windows, a service refers to a program that performs a specific function to support other programs

12 Testing Your Web Server 1. Open your Web browser 2. Type in the Address box, click Enter Apache’s default Web page

13 Testing Your Web Server (continued) 3. Type in the Address box, click Enter Web page informing you that IIS is running

14 Configuring Apache To configure ports and other settings you must edit the httpd.conf file For UNIX/Linux /usr/local/apache2/conf For Windows C:\Program Files\Apache Group\Apache2\conf Lines that begin with the pound sign (#) are informational comments Lines without pound signs contain directives

15 Configuring Apache (continued) httpd.conf

16 Configuring Apache (continued) Directives define information about how a program should be configured The DocumentRoot directive identifies the default directory from where Apache serves Web pages The Alias directive identifies other directories that Apache can use to serve Web pages

17 Configuring Internet Information Services Default Web Site Properties dialog box

18 Configuring Apache for PHP on UNIX/Linux Platforms 1. Open the httpd.conf file from the /usr/local/apache2/conf directory 2. Search for the LoadModule directive : LoadModule php5_module libexec/libphp5.so 3. Add the AddType directive to the end of the file : AddType application/x-httpd-php.php 4. Save and close the httpd.conf file 5. Restart Apache with the command : /usr/local/apache2/bin/apachectl restart

19 Configuring Apache for PHP on Windows 1. Click the Start menu and point to All Programs 2. Select the Edit the Apache httpd.config Configuration File command 3. Add the following to the end of the file: ScriptAlias /PHP/ “C:/PHP/” AddType application/x-httpd-php.php Action application/x-httpd-php “/PHP/php-cgi.exe” 4. Save and close the httpd.conf file 5. Restart Apache and select the Restart command

20 Configuring PHP The php.ini configuration file

21 Testing the MySQL Server 1. Check to see if MySQL is running For UNIX/Linux systems: /usr/local/mysql/bin/mysqld_safe --user=mysql & For Windows, use the Services window 2. Run the mysqladmin version command For UNIX/Linux systems: /usr/local/mysql/bin/mysqladmin version For Windows, change to the C:\Program Files\MySQL\MySQL Server 4.1\bin\ directory and run: mysqladmin version

22 Configuring the Uniform Server php.ini is located in: \UniServer\usr\local\php httpd.conf is located in: \UniServer\usr\local\apache2\conf my is located in: \UniServer\usr\local\mysql

23 Creating Basic PHP Scripts Embedded language refers to code that is embedded within a Web page (XHTML document) PHP code is typed directly into a Web page as a separate section A Web page document containing PHP code must have an extension of.php PHP code is never sent to a client’s Web browser

24 Creating Basic PHP Scripts (continued) The Web page generated from the PHP code, and HTML or XHTML elements found within the PHP file, is returned to the client A PHP file that does not contain any PHP code should have an.html extension.php is the default extension that most Web servers use to process PHP scripts

PHP Block There are four different ways to embed the PHP code echo(“Some PHP code”);

26 Creating PHP Code Blocks Code declaration blocks are separate sections within a Web page that are interpreted by the scripting engine PHP code block is embedded within the tags. When the server encounters the PHP tags it switches from the HTML to PHP mode. There are four types of code declaration blocks: Standard PHP script delimiters The element Short PHP script delimiters ASP-style script delimiters

27 Standard PHP Script Delimiters A delimiter is a character or sequence of characters used to mark the beginning and end of a code segment The standard method of writing PHP code declaration blocks is to use the script delimiters The individual lines of code that make up a PHP script are called statements

28 The Element The element identifies a script section in a Web page document Assign a value of "php" to the language attribute of the element to identify the code block as PHP

29 Short PHP Script Delimiters The syntax for the short PHP script delimiters is Short delimiters can be disabled in a Web server’s php.ini configuration file PHP scripts will not work if your Web site ISP does not support short PHP script delimiters Short delimiters can be used in XHTML documents, but not in XML documents

30 ASP-Style Script Delimiters The syntax for the ASP-style script delimiters is ASP-style script delimiters can be used in XHTML documents, but not in XML documents ASP-style script delimiters can be enabled or disabled in the php.ini configuration file To enable or disable ASP-style script delimiters, assign a value of “On” or “Off ” to the asp_tags directive in the php.ini configuration file

31 Understanding Functions A function is a subroutine (or individual statements grouped into a logical unit) that performs a specific task To execute a function, you must invoke, or call, it from somewhere in the script A function call is the function name followed by any data that the function needs The data (in parentheses following the function name) are called arguments or actual parameters Sending data to a called function is called passing arguments

32 Displaying Script Results To return to the client the results of any processing that occurs within a PHP code block, you must use an echo() statement or the print() statement The echo() and print() statements create new text on a Web page that is returned as a response to a client

33 Displaying Script Results (continued) PHP Diagnostic Information Web page

34 Displaying Script Results (continued) The echo() and print() statements are language constructs of the PHP programming language A programming language construct refers to a built-in feature of a programming language The echo() and print() statements are virtually identical except: The print() statement returns a value of 1 if it is successful It returns a value of 0 if it is not successful

35 Displaying Script Results (continued) Use the echo() and print() statements to return the results of a PHP script within a Web page that is returned to a client A text string, or literal string, is text that is contained within double or single quotation marks To pass multiple arguments to the echo() and print() statements, separate them with commas like arguments passed to a function

36 Creating Multiple Code Declaration Blocks For multiple script sections in a document, include a separate code declaration block for each section... Multiple Script Sections First Script Section Output from the first script section. ”; ?> Second Script Section Output from the second script section. ” ;?>

37 Creating Multiple Code Declaration Blocks (continued) PHP code declaration blocks execute on a Web server before a Web page is sent to a client... Multiple Script Sections First Script Section Output from the first script section. Second Script Section Output from the second script section.

38 Creating Multiple Code Declaration Blocks (continued) Figure 1-9 Output of a document with two PHP script sections

39 Case Sensitivity in PHP Programming language constructs in PHP are mostly case insensitive <?php echo “ Explore Africa, ”; Echo “ South America, ”; ECHO “ and Australia ! ”; ?>

40 Adding Comments to a PHP Script Comments are nonprinting lines placed in code such as: The name of the script Your name and the date you created the program Notes to yourself Instructions to future programmers who might need to modify your work

41 Adding Comments to a PHP Script (continued) Line comments hide a single line of code Add // or # before the text Block comments hide multiple lines of code Add /* to the first line of code And */ after the last character in the code

42 Adding Comments to a PHP Script (continued) <?php /* This line is part of the block comment. This line is also part of the block comment. */ echo “ Comments Example ”; // Line comments can follow code statements // This line comment takes up an entire line. # This is another way of creating a line comment. /* This is another way of creating a block comment. */ ?>

43 Using Variables and Constants The values stored in computer memory are called variables The name you assign to a variable is called an identifier and it: Must begin with a dollar sign ($) Cannot begin with an underscore (_) or a number Cannot include spaces Is case sensitive

44 Declaring and Initializing Variables Specifying and creating a variable name is called declaring the variable Assigning a first value to a variable is called initializing the variable In PHP, you must declare and initialize a variable in the same statement: $variable_name = value;

45 Displaying Variables To print a variable with the echo() statement, pass the variable name to the echo() statement without enclosing it in quotation marks: $VotingAge = 18; Echo $VotingAge; To print both text strings and variables, send them to the echo() statement as individual arguments, separated by commas: echo " The legal voting age is ", $VotingAge, ". ";

46 Displaying Variables To print text strings and variables, you can send them to the echo() statement as one argument enclosed in double quotes: echo " The legal voting age is $VotingAge. "; The legal voting age is 18. To print text strings and the variable name, you can send them to the echo() statement as one argument enclosed in single quotes: echo ‘ The legal voting age is $VotingAge. ’; The legal voting age is $VotingAge

47 Modifying Variables You can modify a variable’s value at any point in a script $SalesTotal = 40; echo " Your sales total is $$SalesTotal "; $SalesTotal = 50; echo " Your new sales total is $$SalesTotal ";

48 Defining Constants A constant contains information that does not change during the course of program execution Constant names do not begin with a dollar sign Constant names use all uppercase letters Use the define() function to create a constant define("CONSTANT_NAME", value); define("VOTING_AGE",18); define("VOTING_AGE",18,TRUE); The value you pass to the define() function can be a text string, number, or Boolean value

PHP Constants..values that never changes Constants are defined in PHP by using the define() function. For e.g. define(“NCST”, “ National Centre for Software Technology ”) defined() function says whether the constant exists or not.

50 Working with Data Types A data type is the specific category of information that a variable contains Data types that can be assigned only a single value are called primitive types

Primitives Four scalar types: Boolean, integer, double, and string Two compound types: array and object Two special types: resource and NULL Integer & double are like those of other languages Boolean -values are true and false (case insensitive)

PHP Data Type Three basic data types Integer Double String More data types Array Object PHP is an untyped language variables type can change on the fly.

PHP Variables The variables in PHP are declared by appending the $ sign to the variable name. For e.g $company = “NCST”; $sum = 10.0; variable’s data type is changed by the value that is assigned to the variable. Type casting allows to change the data type explicitly. Rich set of functions for working with variable. For e.g gettype, settype, isset, unset, is_int, intval etc etc

54 Working with Data Types (continued) The PHP language supports: A resource data type – a special variable that holds a reference to an external resource such as a database or XML file Reference or composite data types, which contain multiple values or complex types of information Two reference data types: arrays and objects

55 Working with Data Types (continued) Strongly typed programming languages require you to declare the data types of variables Static or strong typing refers to data types that do not change after they have been declared Loosely typed programming languages do not require you to declare the data types of variables Dynamic or loose typing refers to data types that can change after they have been declared

56 Numeric Data Types PHP supports two numeric data types: An integer is a positive or negative number with no decimal places (-250, 2, 100, 10,000) A floating-point number is a number that contains decimal places or that is written in exponential notation (-6.16, 3.17, ) Exponential notation, or scientific notation, is short for writing very large numbers or numbers with many decimal places (2.0e11)

57 Boolean Values A Boolean value is a value of true or false It decides which part of a program should execute and which part should compare data In PHP programming, you can only use true or false In other programming languages, you can use integers such as 1 = true, 0 = false

58 Dynamic Typing $Variable = "Hello World"; $Variable = 8; $Variable = 5.367; $Variable = TRUE; $Variable = NULL;

PHP Operators All the operators such as arithmetic, assignment, Comparison, and logical operators are similar to the operators in C and C++. In PHP the string concatenation operator is denoted by ‘.’. For e.g. $name = “My name is”.$myname;

Syntactic Characteristics PHP code can be specified in an HTML document internally or externally: Internally: Externally: include ("myScript.inc") the file can have both PHP and HTML If the file has PHP, the PHP must be in <?php.. ?

Syntactic Characteristics Every variable name begins with a $ Case sensitive Comments -three different kinds (Java and Perl) //... #... /*... */ PHP statements terminated with ; Compound statements are formed with braces Compound statements cannot define locally scoped variables (except functions)

Reserved words of PHP

Arithmetic & Assignment Operators Pre- and Post-Increment and Decrement --, ++

Comparison Operators

Logical Operators

Output Output from a PHP script is HTML that is sent to the browser HTML is sent to the browser through standard output There are three ways to produce output: echo, print, and printf Echo and print take a string, but will coerce other values to strings echo “Hello there!"; echo(“Hello there!”); echo $sum; print "Welcome!"; print(“Wellcome”); print (46);

Assignments 1 List and explain the available Variable handling Functions in php?