Presentation is loading. Please wait.

Presentation is loading. Please wait.

MSc Internet Computing

Similar presentations


Presentation on theme: "MSc Internet Computing"— Presentation transcript:

1 MSc Internet Computing
CSYM010 Server Side Software Lecturer: Espen Svennevik

2 Content Web Servers Common Gateway Interface
Server side scripting languages

3 Scheme of work Tuesday 7th Feb
Webservers, CGI & server side scripting languages- PHP 14th Feb PHP 21st Feb PHP & MySQL 28th Feb 7th March JSP & JDBC or AJAX 14th March ASSIGNMENT 21st March ASSIGNMENT – Hand into AHO by Friday 25th March Easter Break

4 Webserver Apache - Multiplatform Microsoft IIs Jakarta Tomcat
HTTP Protocol Typically TCP Port 80

5 HTTP HyperText Transaction Protocol Version 1.0 or 1.1
Simple text based protocol Client requests Server responds (possibly with an error)

6 HTTP continued - Example
Client: GET /~espen/CSYM010/test.html HTTP/1.0 Server: HTTP/ OK Or HTTP/ Not Found

7 HTTP continued - Example
espen:~ espen$ telnet 80 Trying Connected to my23-1.eng.nene.ac.uk. Escape character is '^]'. GET /~espen/CSYM010/test.html HTTP/1.0 HTTP/ OK Date: Tue, 07 Feb :36:14 GMT Server: Apache/ (Unix) PHP/4.3.10 Last-Modified: Tue, 07 Feb :36:15 GMT ETag: W/"90db db300" Accept-Ranges: bytes Content-Length: 22 Connection: close Content-Type: text/html X-Pad: avoid browser bug <b><i>CSYM0101</i></b>Connection closed by foreign host. espen:~ espen$

8 HTTP continued Common status codes 200 OK
The request succeeded, and the resulting resource (e.g. file or script output) is returned in the message body. 404 Not Found The requested resource doesn't exist. 301 Moved Permanently 302 Moved Temporarily 303 See Other (HTTP 1.1 only) The resource has moved to another URL (given by the Location: response header), and should be automatically retrieved by the client. This is often used by a CGI script to redirect the browser to an existing file. 500 Server Error An unexpected server error. The most common cause is a server-side script that has bad syntax, fails, or otherwise can't run correctly.

9 HTTP continued Other methods apart from GET are: POST - Similar to GET
HEAD - Gets header only - no body

10 Common Gateway Interface (CGI)
Interface to server side scripts Client (browser) request a script Server executes scripts Output of scripts are returned to the client Client (browser) displays (renders) output

11 CGI Example Written in UNIX shell #!/bin/sh
echo "Content-Type: text/html" echo NOW=`date` echo "<h1>Todays date and time is $NOW</h1>"

12 CGI Example - continued
Output Content-Type: text/html <h1>Todays date and time is Tue Feb 7 11:48:09 GMT 2006</h1>

13 Second CGI example #!/bin/sh echo "Content-Type: text/html” echo
for i in do echo "<h$i>Header $i</h$i>” done

14 Second CGI example - cont’
Content-Type: text/html <h1>Header 1</h1> <h2>Header 2</h2> <h3>Header 3</h3> <h4>Header 4</h4> <h5>Header 5</h5> <h6>Header 6</h6>

15 Apache environment variables
Apache passes data to scripts in environment variables. These include: DOCUMENT_ROOT="/var/www/html” GATEWAY_INTERFACE="CGI/1.1" HTTP_ACCEPT="image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*” HTTP_ACCEPT_CHARSET="iso ,*,utf-8” HTTP_ACCEPT_ENCODING="gzip" HTTP_ACCEPT_LANGUAGE="en” HTTP_CONNECTION="Keep-Alive" HTTP_HOST=" ” HTTP_USER_AGENT="Mozilla/4.74 (Macintosh; U; PPC)” PATH="/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin” QUERY_STRING="" REMOTE_ADDR=" "

16 Environment variables
REMOTE_PORT="1740" REQUEST_METHOD="GET” REQUEST_URI="/cgi-bin/printenv” SCRIPT_FILENAME="/var/www/cgi-bin/printenv” SCRIPT_NAME="/cgi-bin/printenv” SERVER_ADDR=" ” SERVER_NAME="radon” SERVER_PORT="80" SERVER_PROTOCOL="HTTP/1.0” SERVER_SIGNATURE="<ADDRESS>Apache/ Server at radon Port 80</ADDRESS>\n” SERVER_SOFTWARE="Apache/ (Unix) (Red Hat/Linux) mod_ssl/2.6.6 OpenSSL/0.9.5a DAV/1.0.1 PHP/4.0.2 mod_perl/1.24"

17 CGI script & environment
#!/bin/sh echo "Content-Type: text/html” echo echo "<h1>Your browser is $HTTP_USER_AGENT</h1>” echo "<h2>Your IP address is $REMOTE_ADDR</h2>” echo "<h2>Your PORT number is $REMOTE_PORT</h2>"

18 CGI script & environment
• Previous script produces this output in the browser window: Your browser is Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv: ) Gecko/ Firefox/ Your IP address is Your PORT number is 51046


Download ppt "MSc Internet Computing"

Similar presentations


Ads by Google