David Lawrence 7/8/091Intro. to PHP -- David Lawrence.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

Other Web Application Development Technologies. PHP.
E-Commerce CMM503 – Lecture 8 Stuart Watt Room C2.
DT228/3 Web Development WWW and Client server model.
Languages for Dynamic Web Documents
Copyright 2004 Monash University IMS5401 Web-based Systems Development Topic 2: Elements of the Web (g) Interactivity.
Server-Side vs. Client-Side Scripting Languages
PHP (2) – Functions, Arrays, Databases, and sessions.
Session 6 Server-side programming - ASP. An ASP page is an HTML page interspersed with server-side code. The.ASP extension instead of.HTM denotes server-side.
B.Sc. Multimedia ComputingMedia Technologies Database Technologies.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic Server Side Web Technologies: Part 2.
Chapter 11 ASP.NET JavaScript, Third Edition. 2 Objectives Learn about client/server architecture Study server-side scripting Create ASP.NET applications.
1 Java Server Pages Can web pages be created specially for each user? What part does Java play?
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)
Web Programming Language Dr. Ken Cosh Week 1 (Introduction)
8/17/2015CS346 PHP1 Module 1 Introduction to PHP.
PHP: Introduction By Trevor Adams.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Server Side Scripting Norman White. Where do we do processing? Client side – Javascript (embed code in html) – Java applets (send java program to run.
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 15: PHP Introduction.
COMP An Introduction to Computer Programming : University of the West Indies COMP6015 An Introduction to Computer Programming Lecture 03.
CSC 318 WEB APPLICATION DEVELOPMENT.  Introduction to Server Scripting language  Client VS Server  Introduction to PHP  PHP Files and Syntax  Function.
INTRODUCTION TO WEB DATABASE PROGRAMMING
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Languages in WEB Presented by: Jenisha Kshatriya BCM SS09.
Chapter 33 CGI Technology for Dynamic Web Documents There are two alternative forms of retrieving web documents. Instead of retrieving static HTML documents,
Basics of Web Databases With the advent of Web database technology, Web pages are no longer static, but dynamic with connection to a back-end database.
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.
Chapter 17 - Deploying Java Applications on the Web1 Chapter 17 Deploying Java Applications on the Web.
PHP With Oracle 11g XE By Shyam Gurram Eastern Illinois University.
NASRULLAH KHAN.  Lecturer : Nasrullah   Website :
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
HTML. Principle of Programming  Interface with PC 2 English Japanese Chinese Machine Code Compiler / Interpreter C++ Perl Assembler Machine Code.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Web Pages with Features. Features on Web Pages Interactive Pages –Shows current date, get server’s IP, interactive quizzes Processing Forms –Serach a.
Active Server Pages  In this chapter, you will learn:  How browsers and servers interacted on the Internet when the Internet first became popular 
CSC 2720 Building Web Applications Server-side Scripting with PHP.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
1 MSCS 237 Overview of web technologies (A specific type of distributed systems)
CS 4720 Dynamic Web Applications CS 4720 – Web & Mobile Systems.
Web Programming Brian Toone 8/27/2014. Outline for today 1.Understanding the architecture of the web 2.Overview of programming languages – Client-side.
Web Pages with Features. Features on Web Pages Interactive Pages –Shows current date, get server’s IP, interactive quizzes Processing Forms –Serach a.
ASP (Active Server Pages) by Bülent & Resul. Presentation Outline Introduction What is an ASP file? How does ASP work? What can ASP do? Differences Between.
CITA 310 Section 7 Installing and Testing a Programming Environment (Textbook Chapter 7)
Web Design and Development. World Wide Web  World Wide Web (WWW or W3), collection of globally distributed text and multimedia documents and files 
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
NASRULLAH KHAN.  Lecturer : Nasrullah   Website :
 Web pages originally static  Page is delivered exactly as stored on server  Same information displayed for all users, from all contexts  Dynamic.
Unit 1 – Web Concepts Instructor: Brent Presley.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 2: Introduction to IS2803 Rob Gleasure
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.
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.
CGS 3066: Web Programming and Design Spring 2016 Introduction to Server-Side Programming.
A S P. Outline  The introduction of ASP  Why we choose ASP  How ASP works  Basic syntax rule of ASP  ASP’S object model  Limitations of ASP  Summary.
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.
1 Chapter 1 INTRODUCTION TO WEB. 2 Objectives In this chapter, you will: Become familiar with the architecture of the World Wide Web Learn about communication.
PHP Basics and Syntax Lesson 3 ITBS2203 E-Commerce for IT.
Introduction to Dynamic Web Programming
WWW and HTTP King Fahd University of Petroleum & Minerals
IntroductionToPHP Static vs. Dynamic websites
Lecture 5: Functions and Parameters
Intro to PHP.
PHP: Hypertext Preprocessor
Hypertext Preprocessor
Web Application Development Using PHP
Presentation transcript:

David Lawrence 7/8/091Intro. to PHP -- David Lawrence

What is PHP?  PHP = PHP: Hypertext Preprocessor (a recursive acronym) 7/8/09Intro. to PHP -- David Lawrence2  “ PHP is an HTML-embedded scripting language. Much of its syntax is borrowed from C, Java and Perl with a couple of unique PHP-specific features thrown in. The goal of the language is to allow web developers to write dynamically generated pages quickly.” = WWW

Viewing sites on the World Wide Web requires both a Server and a Client 6/10/08David Lawrence JLab3 Client software runs on users’ computers Server software runs on a different computer Server sends coded information and the client (browser) decides how to display it.

Decisions, decisions, ….  Dynamic content requires a program to run somewhere.  Should it run server side or client side?  Server side: PHP, ASP (active server pages), JSP (Java sever pages), CGI (common gateway interface) (used for perl).  Client side: HTML, Javascript, ActiveX, FLASH, Applets 7/8/09Intro. to PHP -- David Lawrence4

PHP is a good choice because…  It currently ranks 4 th on the TIOBE Programming Community Index (behind Java, C, and C++)  Well documented and well supported with a shallow learning curve  Server-side is more browser independent than client-side  PHP is open source (i.e. free!) 7/8/09Intro. to PHP -- David Lawrence5

Getting started Note: This tutorial does not cover installation of PHP and configuration of the web server.  PHP code is contained in files stored where the server can access them.  Usually, the server is configured to pass any files with names ending in “.php” through the PHP parser. 7/8/09Intro. to PHP -- David Lawrence6 php goes inhtml comes out  Files can be edited with any text editor (some are better than others)

Hello World! 7/8/09Intro. to PHP -- David Lawrence7 The PHP code is embedded between the tags

Embedding PHP in HTML 7/8/09Intro. to PHP -- David Lawrence8 One easily flow in and out of PHP mode with the tags The parser will replace everything inside the tags with the output of the code they contain Hello World The message of the day is: Hello World! PHP parser PHP file What the browser sees (Browser never actually sees the PHP code!)

Including other files  One can “include” one PHP file in another to recycle code  Multiple options for including files: include(“file.php”) require(“file.php”) include_once(“file.php”) require_once(“file.php”) 7/8/09Intro. to PHP -- David Lawrence9 Usually, you want to use require_once() warn if file not found fatal error if file not found include only once (even if nested includes cause multiple requests)

PHP variables  Variables are always prefixed with a “$”  The variable type is implied by the context of how it’s used (but you generally don’t care exactly what type it is!)  Variable values carry from section to section when parsing file(s) for a single page, but not necessarily when loading a different page  Undefined variables resolve to 0 or an empty string (they don’t give errors!) 7/8/09Intro. to PHP -- David Lawrence10

HTML Forms 7/8/09Intro. to PHP -- David Lawrence11 The tags are a short- hand to printing variables The special variable “$_REQUEST” is an array containing values passed into the script through a form (either POST or GET method) This form just switches the values passed in for word_1 and word_2

Accessing a database with PHP 6/10/08David Lawrence JLab12 PDO = PHP Data Objects

PHP embedded in HTML 6/10/08David Lawrence JLab13

PHP embedded in HTML 6/10/08David Lawrence JLab14

Functions  Large scripts can be made modular using functions Unlike many languages, PHP functions don’t exist until the definition is encountered at runtime! 7/8/09Intro. to PHP -- David Lawrence15

Arrays  Arrays can be created with the array() function The special $var[ ] syntax appends one element to an existing array. foreach can be used to loop over elements of an array. Specific elements can be accessed with $var[0], $var[1], … 7/8/09Intro. to PHP -- David Lawrence16

Sessions  Web pages are ephemeral (in a sense) 7/8/09Intro. to PHP -- David Lawrence17 The PHP code is run and the results sent to the browser The PHP “program” ends and must be run again when the page is again accessed  A “session” provides a way to store variables across pages and accesses to maintain the state of the program a ghost?

Sessions  Start a session with session_start() (this must be done BEFORE anything is printed!)  Store and retrieve variables using the $_SESSION[ ] array 7/8/09Intro. to PHP -- David Lawrence18

Objects  PHP has objects! But… Members are accessed using the “$this” variable Parent constructors and destructors are not automatically called 7/8/09Intro. to PHP -- David Lawrence19

Constructors and Destructors  The constructor method is always called __construct() regardless of the class  The destructor method is always called __destruct() regardless of the class  Parent class ctor/dtor must be explicitly called: parent::__construct() parent::__destruct() 7/8/09Intro. to PHP -- David Lawrence20

Inheritance  A class may inherit another class’ methods and data members by extending it  A class may be abstract meaning it only defines the names and formats of methods (not the contents) 7/8/09Intro. to PHP -- David Lawrence21

An alternative way … 7/8/09Intro. to PHP -- David Lawrence22  The get_class() routine can be used to get the name of the class of an object  Also, self:: and parent:: can be used to explicitly call static methods of the current object’s class or its parent’s

Command Line interface  PHP can be used from the command line without a web server by simply passing the name of the script to the php program 7/8/09Intro. to PHP -- David Lawrence23 Great for debugging!

Summary  PHP is a scripting language primarily geared towards web pages (but can be used from the command line as well )  All major web servers (Apache, MS IIS, …) support PHP and PHP supports all major Databases (MySQL, Oracle, …)  PHP allows both procedural and object oriented programming models  See extensive documentation with examples at: 7/8/09Intro. to PHP -- David Lawrence24