CP3024 Lecture 3 Server Side Facilities. Lecture contents  Server side includes  Common gateway interface (CGI)  PHP Hypertext Preprocessor (PHP) pages.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

1 Database Driven Web Application Clients Application Servers including web servers Database Server Traditional client-server (2-tier architecture): client:
How does the server format the information it gives to the appln program? As environment variables and in standard input.
Website Development Introducing PHP The PHP scripting language Syntax derives from C, Java and Perl Open Source Links to MySql database.
Guide To UNIX Using Linux Third Edition
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
Common Gateway Interface
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
August Chapter 1 - Essential PHP spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science and Technology.
ALBERT WAVERING BOBBY SENG. Week Whatever: PHP  Announcements/questions/complaints.
UFCEKG-20-2 Data, Schemas & Applications Lecture 4 Server Side Scripting & PHP.
Chapter 9 Using Perl for CGI Programming. Computation is required to support sophisticated web applications Computation can be done by the server or the.
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.
PHP == ‘ Hypertext Preprocessor ’ Open-source, server-side scripting language Used to generate dynamic web-pages PHP scripts reside between reserved PHP.
Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.
Overview A plain HTML document is static A CGI program is executed in real-time, so that it can output dynamic information. CGI (Common Gateway Interface)
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
PHP H ypertext P re-processor. Unit 6 - PHP - Hello World! - Data types - Control structures - Operators.
AIT 616 Fall 2002 PHP. AIT 616 Fall 2002 PHP  Special scripting language used to dynamically generate web documents  Open source – Free!!!  Performs.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
Chapter 33 CGI Technology for Dynamic Web Documents There are two alternative forms of retrieving web documents. Instead of retrieving static HTML documents,
INTERNET APPLICATION DEVELOPMENT For More visit:
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
Nic Shulver, Intro: Developing Server Applications What is a server? Many types of server – File server – file: networked file.
Nael Alian Introduction to PHP
Web Server Design Week 14 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin Klein 4/14/10.
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
USING PERL FOR CGI PROGRAMMING
1 In the good old days... Years ago… the WWW was made up of (mostly) static documents. –Each URL corresponded to a single file stored on some hard disk.
CSCE Systems Programming Lecture 21 Web Server: CGI -Dynamic Pages CSCE March 25, 2013.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
November 2003Bent Thomsen - FIT 6-11 IT – som værktøj Bent Thomsen Institut for Datalogi Aalborg Universitet.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
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.
Website Development with PHP and MySQL Saving Data.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
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.
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.
Form Data Encoding GET – URL encoded POST – URL encoded
Server-Side Scripting with PHP ISYS 475. PHP Manual Website
Introduction to PHP.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
Copyright © 2002 ProsoftTraining. All rights reserved. Java Servlets.
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.
 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.
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
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.
Introduction to CGI PROG. CGI stands for Common Gateway Interface. CGI is a standard programming interface to Web servers that gives us a way to make.
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.
CGS 3066: Web Programming and Design Spring 2016 PHP.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
Scott Marino MSMIS Summer Session Web Site Design and Authoring Session 13 Scott Marino.
PHP using MySQL Database for Web Development (part II)
PHP (PHP: Hypertext Preprocessor)
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
PHP / MySQL Introduction
PHP Introduction.
PHP.
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Tutorial 6 PHP & MySQL Li Xu
Environment Variables
PHP: Hypertext Preprocessor
PHP an introduction.
Presentation transcript:

CP3024 Lecture 3 Server Side Facilities

Lecture contents  Server side includes  Common gateway interface (CGI)  PHP Hypertext Preprocessor (PHP) pages

Static HTML Page  Page created and stored on server  Delivered to browser when requested  Page always remains the same

Dynamic Content Generated by the Server  Browser requests page  Page is generated “on the fly”  Content depends on: –Request made –Time of day –Etc.

“On-the-fly” Content Server Client Request HTML generated “on- the-fly”

Server Side Includes(SSI)  Directives placed in an HTML page  When page is delivered server inserts extra information  Browser only sees final HTML version  Not supported by all server software  Pages have special suffix (normally.shtml)

Directive Format  e.g.

Permitted Directives  config  echo  exec  flastmod  fsize  include  printenv  set

echo  echo var= “environment_variable”  Inserts the value of special side include variables into page e.g. My server is called

Running echo

exec  Used to execute a command or a user program  Best if program generates HTML  Can’t send data to program exec cmd|cgi=“string”

Running exec

fsize  Inserts the size of a named file  Useful for warning about size of graphics etc. fsize file|virtual=“path”

flastmod  Inserts the last modified date for a named file  Used to indicate how up to date the information is flastmod file=“path”

Running fsize and flastmod

include  Use to include text (normally html) into a file  Can be used to add standard text to pages include file|virtual=“path”

Common Gateway Interface  Known as CGI  One of the most misunderstood Web technologies  Allows client to pass data to programs running on server  Programs generate HTML to be returned to browser

CGI in action Program Client Server HTTP Request Data for program Generated HTML HTML

What is a CGI program?  Can be written in any language  CGI defines the format of the data passed to the program  Program reads data from an environment variable called QUERY_STRING  Program generates output prefixed by Content- type: header. E.g.: echo Content-type: text/html echo

URL encoding  Data may be sent via GET or POST  Values are encoded as variable/value pairs  Each pair is separated by & –firstname=Joe&lastname=Bloggs  CGI program must decode this string  GET strings go into the server logs but POST strings are not logged

CGI Environment Variables  AUTH_TYPE  CONTENT_LENGTH  CONTENT_TYPE  DOCUMENT_ROOT  GATEWAY_INTERFACE  HTTP_ACCEPT  HTTP_COOKIE  HTTP_FROM  HTTP_REFERER  PATH_INFO  PATH_TRANSLATED  QUERY_STRING  REMOTE_ADDR  REMOTE_HOST  REMOTE_IDENT  REMOTE_USER  REQUEST_METHOD  SCRIPT_NAME  SERVER_NAME  SERVER_PORT  SERVER_PROTOCOL  SERVER_SOFTWARE

Identifying CGI Scripts  Some server set-ups require script to be stored in /cgi-bin  Other set-ups allow scripts anywhere –Script names have format ????.cgi  Scripts should be made executable for the server username  Apache server username is nobody

Load On Server  Originally each CGI script ran as a separate process  Very costly on server resources  Newer mechanisms run scripts in threads  Server designers ensure that CGI routines cannot crash the Web server

Server-side Scripting  CGI programs generate HTML  Server side script languages embed code within HTML  Server executes code before delivering to browser  Examples include PHP, ASP, JSP and XSP  Requires additional server software

PHP  PHP Hypertext Preprocessor  Server-side, HTML-embedded, cross- platform scripting language  Available as Unix Apache module  CGI version works with IIS on MS Windows  Similar to C or Perl

Embedding PHP in HTML  Between tags –  Between tags for XML –  In tags – echo “Hello World”;

Switching between PHP and HTML  Can be done as and when:

PHP Comments  /* C style comment */  // C++ style comments  # Unix shell style comments

Variables in PHP  All names begin with $ e.g. $variable  Alphabetic character or underscore (_) must follow $  Remaining chars are alphanumeric or underscore  Names are case-sensitive $A is not $a  Types determined by first assignment

Data Types in PHP  Integer –Whole numbers –2,147,483,648 to 2,147,483,647  Floating Point –Decimal values in the range 1.7E-308 to 1.7E308  String –Sequence of characters e.g. “Hello World”  Can convert using setype() function or by casting: –settype($myInt, “string”) –(integer) $myString

String Handling  Characters within strings can be obtained via subscripting  Subscripts start at 0 $hello = “Hello World” $hello[1] will be “e”

Outputting A String  The function echo() outputs a string to the standard output e.g. echo(“Hello World”); echo($astring)

Finding the length of a string  The function strlen() returns a string’s length $hello=“Hello World” The value of strlen($hello) is 11

Getting a number from a string  Use the string in a calculation  PHP converts as much as it can to a number $var=“1234” $num=$var[2] + 5 $num contains the number 8

Expressions  Includes normal arithmetic operations –$i=$i+1 or $i++ –$i=$i-1 or $i-- –Also / (divide) and * (multiply) –% is the modulo operation  May use brackets to specify precedence  Statements separated by semi-colons  Expressions evaluate to true or false

Control Structures  Standard syntax for creating loops –if –switch –while –do/while –for

if statement  if (expression) { statements } elseif (expression) { statements } else { statements }

Conditional expressions  Standard comparison operators =, >, ==, !=  Note the ==  Any numeric expression which has a value of 0 is false otherwise it is true

Can combine conditiond  Logical connectors && and ||  ($var 4) –Variable is less than 6 AND greater than 4  ($var==6) || ($var==4) –Variable is equal to 4 OR equal to 6

if Example if ($var==56){ echo “It’s the same”; } elseif($var<56){ echo “Less than”; } else{ echo “Greater than”; }

for loop  for (start_expr; cond_expr; iter_expr){ statements }  Executes the statements while the cond_expr is true

for example for($var=0; $var<=12; $var++){ echo($var); }

Getting Data From The Client  Data is often supplied to server side programs via HTML forms  Indicated by the tag  Specifies HTTP method and field names  Field names become variables in PHP scripts –Field name myfield becomes $myfield

A Simple Form Multiply Form Enter multiplier

Simple Form Output

PHP Script Times Table <?for($i=1;$i<=12;$i++){ echo($i); ?> * =

Output

Getting It On the Server  Treat PHP scripts like ordinary HTML pages  Except save in files called.php  Suitably equipped Web Server does the rest

Other Resources      Chapter 29 (PHP) - Internet & World Wide Web – How to Program, H.M.Deitel, P.J.Deitel & T.R.Nieto (2 nd edition)

Summary  Dynamic pages generated by the server –Server Side Includes –Common Gateway Interface –PHP