Nic Shulver, [email protected] Intro: Developing Server Applications What is a server? Many...

13
Nic Shulver, [email protected] Intro: Developing Server Applications What is a server? Many types of server – File server – file: networked file space. FTP server – ftp: remote file space, often read-only. Web server – http: web pages and more. Mail server – mail: email system. News server – news: newsgroups messages, used to be huge.

Transcript of Nic Shulver, [email protected] Intro: Developing Server Applications What is a server? Many...

Page 1: Nic Shulver, N.A.Shulver@staffs.ac.uk Intro: Developing Server Applications What is a server? Many types of server – File server – file: networked file.

Nic Shulver, [email protected]

Intro: Developing Server ApplicationsWhat is a server?

Many types of server –File server – file: networked file space.FTP server – ftp: remote file space, often

read-only.Web server – http: web pages and more.Mail server – mail: email system.News server – news: newsgroups messages,

used to be huge.

Page 2: Nic Shulver, N.A.Shulver@staffs.ac.uk Intro: Developing Server Applications What is a server? Many types of server – File server – file: networked file.

Nic Shulver, [email protected]

Intro: Developing Server ApplicationsWeb Servers

Web servers used to be very simple:Accept requests for information,Respond with static HTML pages and graphics.

Now servers can be “asked” to run programs on the server

Originally called Common Gateway Interface (CGI) applications, now superseded by ISAPI/NSAPI.

CGI/ISAPI/NSAPI programs use resources on the server to output information to the client browser.

Page 3: Nic Shulver, N.A.Shulver@staffs.ac.uk Intro: Developing Server Applications What is a server? Many types of server – File server – file: networked file.

Nic Shulver, [email protected]

Intro: Developing Server ApplicationsServers: IIS, Apache

Internet Information ServerCommercial server for WindowsComes with XP Pro on the install CD as an extra

Apache (http://www.apache.org/)Free, open-source softwareWidely used, Linux/Unix/Mac/Windows supportEasy to use on a stand-alone PC

Page 4: Nic Shulver, N.A.Shulver@staffs.ac.uk Intro: Developing Server Applications What is a server? Many types of server – File server – file: networked file.

Nic Shulver, [email protected]

Intro: Developing Server ApplicationsWhy “CGI”?

Common - all server platforms use this standard.Gateway - controlled access to the server’s

processing resources.Interface - client-server resource connector function.CGI - a method that allows data to be executed or

interpreted instead of just delivered and displayed.NB Modern ISAPI/NSAPI is much more efficient than

the original CGI.

Page 5: Nic Shulver, N.A.Shulver@staffs.ac.uk Intro: Developing Server Applications What is a server? Many types of server – File server – file: networked file.

Nic Shulver, [email protected]

Intro: Developing Server ApplicationsHTML vs. CGI

“http://gawain.soc.staffs.ac.uk/~cmtnas/homepage.htm”

This reference asks the server (Gawain) to look in the (shortcut to the) cmtnas directory...

... and find a file called “homepage.htm”.The simple server knows that .htm and .html files are

HTML and must be sent, without further processing, to the browser.

Some servers also check for “commands” inside the HTML – often SSI, “server-side includes”.

Page 6: Nic Shulver, N.A.Shulver@staffs.ac.uk Intro: Developing Server Applications What is a server? Many types of server – File server – file: networked file.

Nic Shulver, [email protected]

Intro: Developing Server ApplicationsHTML vs. CGI

http://fred.co.uk/scripts/debug.php.This reference asks the server (fred.co.uk) to

look in the (shortcut to the) scripts directory...... and find a file called “debug.php”.The server knows that a .php file is a page

with embedded script and must be executed by the Web server software as a sub-process.

Any output from running the script is sent to the browser.

Page 7: Nic Shulver, N.A.Shulver@staffs.ac.uk Intro: Developing Server Applications What is a server? Many types of server – File server – file: networked file.

Nic Shulver, [email protected]

Intro: Developing Server ApplicationsCGI+ languages

Web server programming can be accomplished using many suitable languages.

Popular ones are;Modern: PHP (.php), VBScript or JScript (in

ASP, .asp), ASP.NET (.aspx)Java Server Pages (.jsp)Old CGI: perl (.pl), C, C++, any “normal”

programming language (.exe)

Page 8: Nic Shulver, N.A.Shulver@staffs.ac.uk Intro: Developing Server Applications What is a server? Many types of server – File server – file: networked file.

Nic Shulver, [email protected]

Intro: Developing Server ApplicationsPHP

PHP means “PHP Hypertext Pre-processor” (sic).Originally it was known as “Personal Home Pages”

but that is poor for marketing as a business solution!It was also called “perl Hypertext Pre-processor” but

PHP is no longer just a web-version of perl.The PHP language is a mixture of C, perl and others.PHP is supported on many platforms (Mac, PC,

Linux…).

Page 9: Nic Shulver, N.A.Shulver@staffs.ac.uk Intro: Developing Server Applications What is a server? Many types of server – File server – file: networked file.

Nic Shulver, [email protected]

Intro: Developing Server ApplicationsWhat’s it for?

A plain HTML document that the Web server delivers is static, which means it doesn't change.

A CGI program, on the other hand, is executed in real-time, so that it can output dynamic information.

CGI allows someone visiting your Web site to run a program on your machine that performs a specified task – maybe updating a weather report or grabbing a digital photo.

E-Commerce, blogs, web services, discussion areas… many use PHP.

Page 10: Nic Shulver, N.A.Shulver@staffs.ac.uk Intro: Developing Server Applications What is a server? Many types of server – File server – file: networked file.

Nic Shulver, [email protected]

Intro: Developing Server ApplicationsPHP – print all server variables

<html><body><h2>All $_SERVER settings</h2><?php

foreach($_SERVER as $key=>$sItem){ echo "$key = [$sItem]<br>\n";}

?></body></html>

Page 11: Nic Shulver, N.A.Shulver@staffs.ac.uk Intro: Developing Server Applications What is a server? Many types of server – File server – file: networked file.

Nic Shulver, [email protected]

Intro: Developing Server ApplicationsExample Script Output (fragment)

SCRIPT_NAME = [/phpTest/test.php]QUERY_STRING = []REMOTE_USER = [DEXTER\nic]REQUEST_METHOD = [GET]SERVER_PORT = [80]SERVER_PROTOCOL = [HTTP/1.1]SERVER_SOFTWARE = [Microsoft-IIS/5.1]REQUEST_URI = [/phpTest/test.php]URL = [/phpTest/test.php]SCRIPT_FILENAME = [c:\inetpub\wwwroot\phpTest\test.php]ORIG_PATH_INFO = [/phpTest/test.php]

Page 12: Nic Shulver, N.A.Shulver@staffs.ac.uk Intro: Developing Server Applications What is a server? Many types of server – File server – file: networked file.

Nic Shulver, [email protected]

Intro: Developing Server ApplicationsRaw CGI data - encoding

Information is sent from a form to a script in a very odd format.

If field “name” has the value “G Singh”...and “job” has the value “principal lecturer”...the script will receive the string

“name=G%20Singh&job=principal%20lecturer”.But PHP splits this up for you and makes it easy to

use, so you don’t usually worry about it.

Page 13: Nic Shulver, N.A.Shulver@staffs.ac.uk Intro: Developing Server Applications What is a server? Many types of server – File server – file: networked file.

Nic Shulver, [email protected]

Intro: Developing Server ApplicationsSummary

We have briefly met different types of server.We have discussed the reasons for needing CGI+.… and contrasted plain HTML with dynamically

created content.We have noted the wide range of CGI+ languages in

use on the Internet.… and looked at a specific language, PHP.We have briefly considered standard URL-encoded

parameters.