Web Server Scripting

Download Report

Transcript Web Server Scripting

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.
 Servers can be “asked” to run “service” programs
 Originally called Common Gateway Interface (CGI)
applications, now largely superseded by
FastCGI, SimpleCGI
Apache plugins,
Netscape NSAPI or Microsoft ISAPI
Nic Shulver, [email protected]
Intro: Developing Server Applications
Servers: IIS, Apache
Internet Information Server (24.5%, Mar 2010)
Commercial server for Windows
Came with XP Pro on the install CD as an extra
Also available with Vista and Windows 7
Apache (54.5%, Feb 2010)
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 The modern replacements are much more
efficient than the original CGI, yet still compatible.
Nic Shulver, [email protected]
Intro: Developing Server Applications
HTML vs. CGI
“http://www.fcet.staffs.ac.uk/nas1/homepage.htm”
 This reference asks the server (fcet) to look in the
(shortcut to the) nas1 directory...
 ... and find a file called “homepage.htm”.
 The simple server knows that .htm and .html files are
HTML
 It sends the files, without further processing, to the
browser.
 More complex servers can do much more.
Nic Shulver, [email protected]
Intro: Developing Server Applications
HTML vs. CGI
 http://fred.co.uk/scripts/debug.php
 This reference asks the server (fred, a
commercial server in the 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 run by the Web
server software in a special way
 Output from 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
<?php
phpinfo(32);
?>
 This looks suspiciously simple!
 PHPinfo() is a built in function that reports all sorts
of information
 The “32” tells the function to show us the values
of the server variables
Nic Shulver, [email protected]
Intro: Developing Server Applications
PHP – print all server variables

PHP Variables
Variable
Value
_SERVER["ALL_HTTP"]
HTTP_CONNECTION:Keep-Alive HTTP_ACCEPT:*/*
HTTP_ACCEPT_ENCODING:gzip, deflate
HTTP_ACCEPT_LANGUAGE:en-gb
HTTP_HOST:fcetdev1.student.staffs.ac.uk
HTTP_USER_AGENT:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;
.NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET
CLR 3.5.30729; .NET CLR 4.0.20506) HTTP_UA_CPU:x86
_SERVER["HTTPS"]
off
_SERVER["SCRIPT_NAME"]
/wwwdata/nas1/DSAtest01/info.php
_SERVER["HTTP_COOKIE"]
no value
_SERVER["AUTH_PASSWORD"]
no value
_SERVER["AUTH_TYPE"]
no value
_SERVER["AUTH_USER"]
no value
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
 There are 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]
Intro: Developing Server Applications
References (Checked: Aug 2010)
 Common Gateway Interface
(http://en.wikipedia.org/wiki/Common_Gateway_Interface)
 Apache HTTP Server
(http://en.wikipedia.org/wiki/Apache_HTTP_Server)
 The Apache HTTP Server Project
(http://httpd.apache.org/ABOUT_APACHE.html)
 MS Internet Information Services
(http://en.wikipedia.org/wiki/Internet_Information_Services)
 The Official Microsoft IIS Site
(http://www.iis.net/overview)
Nic Shulver, [email protected]
Intro: Developing Server Applications
References (Checked: Aug 2010)
 PHP
(http://en.wikipedia.org/wiki/Php)
 PHP: Hypertext Preprocessor
(http://www.php.net/)
 MySQL, the world's most popular open source
database
(http://www.mysql.com/?bydis_dis_index=1)
Nic Shulver, [email protected]