COMP284 Scripting Languages Handouts
COMP284 Scripting Languages
Lecture 9: PHP (Part 1)
Handouts
Ullrich Hustadt
Department of Computer Science
School of Electrical Engineering, Electronics, and Computer Science
University of Liverpool
Contents
1 PHP
Motivation
2 Overview
Features
Applications
3 Types and Variables
Types
Variables
Type juggling and Type casting
Comparisons
COMP284 Scripting Languages Lecture 9 Slide L9 1
PHP Motivation
Common Gateway Interface CGI
The Common Gateway Interface (CGI) is a standard method for web
servers to use external applications, a CGI program, to dynamically
generate web pages
1 A web client generates a client request, for example, from a HTML
form, and sends it to a web server
2 The web server selects a CGI program to handle the request,
converts the client request to a CGI request, executes the program
3 The CGI program then processes the CGI request and the server passes
the programs response back to the client
COMP284 Scripting Languages Lecture 9 Slide L9 2
PHP Motivation
Disadvantages of CGI/Perl
A distinction is made between static web pages and
dynamic web pages created by an external program
Using Perl scripting it is difficult to add a little bit of
dynamic content to a web page
can be alleviated to some extent by using here documents
Use of an external program requires
starting a separate process every time an external program is requested
exchanging data between web server and external program
; resource-intensive
If our main interest is the creation of dynamic web pages,
then the scripting language we use
should integrate well with HTML
should not require a web server to execute an external program
COMP284 Scripting Languages Lecture 9 Slide L9 3
Overview Features
PHP
PHP is (now) a recursive acronym for PHP: Hypertext Preprocessor
Development started in 1994 by Rasmus Lerdorf
Originally designed as a tool for tracking visitors at Lerdorfs website
Developed into full-featured, scripting language for
server-side web programming
Inherits a lot of the syntax and features from Perl
Easy-to-use interface to databases
Free, open-source
Probably the most widely used server-side web programming language
Negatives: Inconsistent, muddled API; no scalar objects
The departmental web server uses PHP 5.6.25 (released August 2014)
PHP 7 was released in December 2015 (PHP 6 was never released)
COMP284 Scripting Languages Lecture 9 Slide L9 4
Overview Features
PHP processing
Server plug-ins exist for various web servers
; avoids the need to execute an external program
PHP code is embedded into HTML pages using tags
; static web pages can easily be turned into dynamic ones
PHP satisfies the criteria we had for a good web scripting language
Processing proceeds as follows:
1 The web server receives a client request
2 The web server recognizes that the client request is for
a HTML page containing PHP code
3 The server executes the PHP code, substitutes output
into the HTML page, the resulting page is then send to the client
As in the case of Perl, the client never sees the PHP code,
only the HTML web page that is produced
COMP284 Scripting Languages Lecture 9 Slide L9 5
Overview Applications
PHP: Applications
Applications written using PHP
activeCollab Project Collaboration Software
http://www.activecollab.com/
Drupal Content Management System (CMS)
http://drupal.org/home
Magento eCommerce platform
http://www.magentocommerce.com/
MediaWiki Wiki software
http://www.mediawiki.org/wiki/MediaWiki
Moodle Virtual Learning Environment (VLE)
http://moodle.org/
Sugar Customer Relationship Management (CRM) platform
http://www.sugarcrm.com/crm/
WordPress Blogging tool and CMS
http://wordpress.org/
COMP284 Scripting Languages Lecture 9 Slide L9 6
http://www.activecollab.com/
http://drupal.org/home
http://www.magentocommerce.com/
http://www.mediawiki.org/wiki/MediaWiki
http://moodle.org/
http://www.sugarcrm.com/crm/
http://wordpress.org/
Overview Applications
PHP: Websites
Websites using PHP:
Delicious social bookmarking
http://delicious.com/
Digg social news website
http://digg.com
Facebook social networking
http://www.facebook.com
Flickr photo sharing
http://www.flickr.com
Frienster social gaming
http://www.frienster.com
SourceForge web-based source code repository
http://sourceforge.net/
Wikipedia collaboratively built encyclopedia
http://www.wikipedia.org
COMP284 Scripting Languages Lecture 9 Slide L9 7
http://delicious.com/
http://digg.com
http://www.facebook.com
http://www.flickr.com
http://www.frienster.com
http://sourceforge.net/
http://www.wikipedia.org
Overview Applications
Recommended texts
R. Nixon:
Learning PHP, MySQL, and JavaScript.
OReilly, 2009.
Harold Cohen Library: 518.561.N73 or e-book
(or later editions of this book)
M. Achour, F. Betz, A. Dovgal, N. Lopes,
H. Magnusson, G. Richter, D. Seguy, J. Vrana, et al.:
PHP Manual.
PHP Documentation Group, 2018.
http://www.php.net/manual/en/index.php
COMP284 Scripting Languages Lecture 9 Slide L9 8
http://www.php.net/manual/en/index.php
Overview Applications
PHP: Hello World!
1
2
3
4
Our first PHP script
5 Hello World!
);
7 ?>
8
Reviews
There are no reviews yet.