Intro: Developing Server Applications

Download Report

Transcript Intro: Developing Server Applications

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.
Nic Shulver, [email protected]
Intro: Developing Server Applications
Web 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.
Nic Shulver, [email protected]
Intro: Developing Server Applications
Servers: IIS, Apache
Internet Information Server
Commercial server for Windows
Comes with XP Pro on the install CD as an extra
Apache (http://www.apache.org/)
Free, open-source software
Widely used, Linux/Unix/Mac/Windows support
Easy to use on a stand-alone PC
Nic Shulver, [email protected]
Intro: Developing Server Applications
Why “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.
Nic Shulver, [email protected]
Intro: Developing Server Applications
HTML 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”.
Nic Shulver, [email protected]
Intro: Developing Server Applications
HTML 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.
Nic Shulver, [email protected]
Intro: Developing Server Applications
CGI+ 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)
Nic Shulver, [email protected]
Intro: Developing Server Applications
PHP
 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…).
Nic Shulver, [email protected]
Intro: Developing Server Applications
What’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 realtime, 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.
Nic Shulver, [email protected]
Intro: Developing Server Applications
PHP – print all server variables
<html>
<body>
<h2>All $_SERVER settings</h2>
<?php
foreach($_SERVER as $key=>$sItem)
{
echo "$key = [$sItem]<br>\n";
}
?>
</body>
</html>
Nic Shulver, [email protected]
Intro: Developing Server Applications
Example 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]
Nic Shulver, [email protected]
Intro: Developing Server Applications
Raw 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.
Nic Shulver, [email protected]
Intro: Developing Server Applications
Summary
 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.
Nic Shulver, [email protected]