39
Computer Net Lab/Praktikum Datenverarbeitung 2 1 Overview Overview • Internet • Internet Protocols • Fundamentals about HTTP Communication • HTTP-Server, mode of operation • Static/Dynamic Webpages • HTML • PHP programming

Computer Net Lab/Praktikum Datenverarbeitung 2 1 Overview Internet Internet Protocols Fundamentals about HTTP Communication HTTP-Server, mode of operation

Embed Size (px)

Citation preview

Computer Net Lab/Praktikum Datenverarbeitung 2 1

OverviewOverview

• Internet • Internet Protocols• Fundamentals about HTTP Communication • HTTP-Server, mode of operation• Static/Dynamic Webpages• HTML• PHP programming

Computer Net Lab/Praktikum Datenverarbeitung 2 2

InternetInternet

Client

Connectionvia

TCP/IP-Protocol

Internet

Server

Text, Audio, Video and Graphics

Computer Net Lab/Praktikum Datenverarbeitung 2 3

HistoryHistory

• The WWW is 18 years old• On the 30th April 1993 the originator of the WWW Tim Berners-

Lee declared: Everyone is allowed to use the World Wide Web and all possibilities it offers without any licenses. Eine gute Idee.

Computer Net Lab/Praktikum Datenverarbeitung 2 4

Internet ServicesInternet Services

• E-Mail• WWW• Chat • Internet News• FTP• Telnet• Applications

Internet

Computer Net Lab/Praktikum Datenverarbeitung 2 5

Internet ProtocolsInternet Protocols

Internet

• HTTP• HTTPS• FTP• SMTP• NNTP

Server

Data

Client

Connection via Internet Protocol

Computer Net Lab/Praktikum Datenverarbeitung 2 6

ProtocolsProtocols

HTTP FTP SMTPApplication

TCP UDPTransport

IPInternet

Ethernet Token-Ring ATMPhys. Network

DNS SNMP RIP

Computer Net Lab/Praktikum Datenverarbeitung 2 7

http (Hypertext Transfer Protocol)http (Hypertext Transfer Protocol)

• Two Types of http messages: Request, Response• Requests:

– Request method i.e.: Get, Post– wanted URL– HTTP-Protocol version (actual 1.1)– Headerinfo i.e.: which documents could be received by the client

• Responses:– Status messages i.e.: 200 : OK, 404: File Not Found– Headerinfo i.e.: Content-Length, Content-Type (Text, Html, etc.)– The requested document

Computer Net Lab/Praktikum Datenverarbeitung 2 8

http (Interaction)http (Interaction)

• HTTP Interaction Principles :– Connection establishment

TCP-Connection from Client to Server (usually Port 80 on the Server)– Request from Client to Server

Method selectionadditional parameters for the method

– Response from Server to ClientResult as a status codeadditional parameters on the result

– Connection terminationusually ending the connectionnewer versions (newer then HTTP/1.1) can keep connection longer alive

Computer Net Lab/Praktikum Datenverarbeitung 2 9

http (Methods)http (Methods)

• OPTIONS requests server features• GET fetch a resource from server• HEAD provides only meta information about a resource• PUT saves a resource• POST sends a data set to a resource (CGI-Script)• DELETE deletes a resource• TRACE allows tracking of the processing of requests

Computer Net Lab/Praktikum Datenverarbeitung 2 10

https (1)https (1)

• Widely used security technology

• http-Server accepts ssl (secure socket-layer) connection

• Identification of secure connection viahttps://url

• SSL connection uses port 443

• Transmitted data are quasi tap-proof (key length)

• Higher working load on server, because encryption causes additional computing time

Computer Net Lab/Praktikum Datenverarbeitung 2 11

https (2)https (2)

HTTPSApplication

SSLSecurity

TCPTransport

IPInternet

Ethernet Token Ring ATMPhys. Network

Computer Net Lab/Praktikum Datenverarbeitung 2 12

Client Server PrincipleClient Server Principle

WebserverClient with Webbrowser

Netzwerk

TCP/IPTCP/IP TCP/IPTCP/IP

HTTPHTTP

IP-AdresseIP-Adresse

http request

http answer

Request over

Results

Computer Net Lab/Praktikum Datenverarbeitung 2 13

URLURL

• URL = unified resource locator• The access to the server is done by the URL• Format:

access_method://computerername:port/document?querystring• Example:

http://www.uni-duisburg.de/netlab/student.php?matr=123456– access method: http– computer name: fb9dv.uni-duisburg.de– port: standard port (80 for HTTP), here not specified– document: netlab/students.html (path/filename)– Query string: matr=123456

Computer Net Lab/Praktikum Datenverarbeitung 2 14

Domain namesDomain names

• Domain name: fb9dv.uni-duisburg.de– de: first layer name (top-level-domain)– uni-duisburg: second layer name– fb9dv: third layer name

dede

fb9dv.uni-duisburg.defb9dv.uni-duisburg.de

uni-duisburg.deuni-duisburg.de

iis.uni-duisburg.de

Computer Net Lab/Praktikum Datenverarbeitung 2 15

Port communicationPort communication

• communication via TCP/IP operates by IP-Addresses and Ports• each IP-Adresse has 2

16 potential ports

• The ports below 1024 are standardized (standard ports), which are allocated to dedicated services, i.e.:23 telnet25 smtp80 http443 https

134.91.100.1

23 25 80 30000. . . . . . . .

Computer Net Lab/Praktikum Datenverarbeitung 2 16

Query GET/POSTQuery GET/POST

• Data transfer to server• Data are computed by the server and the resulted page is sent to

the client• Two procedures: Get and Post method

• Get: Query-String is specified within the url http://www.uni-duisburg.de/student.php?name=peter

• Post: Data are transmitted in HTTP query’s body (not in url)Example: form data

Computer Net Lab/Praktikum Datenverarbeitung 2 17

HTTP-Server (1)HTTP-Server (1)• Document Root Folder

root directory where all files for the website are stored• Documents are organized in directories• Access rights are considered

read, write, deletepublic accessed web pages have to be readable by everyone, in terms of access rights

• Definition of standard documents like index.html, start.htm• Modular structured, additional services like php-Modul can be

integrated• Multiple configurations i.e.

- directory level control- allow access only from specific IP-Addresses

Computer Net Lab/Praktikum Datenverarbeitung 2 18

HTTP-Server (2)HTTP-Server (2)

• Apache-Server configuration is done using the file httpd.conf. This file is read in and evaluated when starting the servers

• Contains information about the Apache Web-Server itself, about logs and additional configuration files. Examples:– ServerRoot

The statement ServerRoot defines the path to the top level directory, which includes configuration folders and files, log-files and documents.

– DocumentRootThe document folder is the directory, where the server tries to locate the file, in case no path was specified within the url. Only one DocumentRoot can be defined in the resource list of the Apache Web-Servers.

– UserDirUserDir makes it possible for the web-server to access documents out of the user’s home directory. Example: http:/server/~username/document.htm

Computer Net Lab/Praktikum Datenverarbeitung 2 19

HTTP-Server (3)HTTP-Server (3)

Configuration panel for IIS (Windows 2000)

Computer Net Lab/Praktikum Datenverarbeitung 2 20

Static Internet PagesStatic Internet Pages• Pages (content) are already available before they are requested• Pages are quickly available• The Server does not need any additional services (applications)

like: Interpreter, Database. • Interaction with Server is limited to links• Pages can be computed, respectively displayed, on the client

computer, without any additional procedures

Computer Net Lab/Praktikum Datenverarbeitung 2 21

HTML (1)HTML (1)

• HTML (Hypertext Markup Language)• Markup language: it describes the logical part of a text oriented document.• HTML offers the possibility to define typical elements of a text oriented

document, like: header, paragraphs, lists, tables or graphical references.• Advantages:

– HTML is a so called clear text format (can be edited with every text editor)– Easy to learn

• Disadvantages:– No separation between form and content– Design and Interaction possibilities are limited

Computer Net Lab/Praktikum Datenverarbeitung 2 22

HTML (2)HTML (2)

<html><head> <title>Beispiel 1</title></head><body>Textfeld<br></body></html>

Browser

Computer Net Lab/Praktikum Datenverarbeitung 2 23

Dynamic Internet Pages (Server1)Dynamic Internet Pages (Server1)

• Page content is generated (immediately) after request• Access may be slower, due to the need of page generation• System has to have adequate resources• Optional applications possible

– Database access– Graphics generation– Access of processes (application), which offer interfaces

• General 2 methods– GGI (Common Gateway Interface)

i.e.: perl, c++– As a modul (server extension)

i.e.: php

Computer Net Lab/Praktikum Datenverarbeitung 2 24

Dynamic Internet Pages (Server2)Dynamic Internet Pages (Server2)

DBCGI

Server

GeneratedHTML-File

Request

Client

GeneratedHTML-File

Computer Net Lab/Praktikum Datenverarbeitung 2 25

Dynamic Internet Pages (Client)Dynamic Internet Pages (Client)

• DHTML• Browser can execute (interpret) scripts, which are included in

HTML-Files.• By the use of a script language a dynamic page can be created

on the client.• Example: JavaScript (Browser independent)

Alternatively JavaScript can be embedded in the HTML-File or it can be located in a separate file. JavaScript is interpreted by the web browser at runtime. Therefore modern web browser have an interpreter software integrated.Example

Computer Net Lab/Praktikum Datenverarbeitung 2 26

SessionsSessions

• HTTP is a stateless protocol• After the request (and response) for a web page the connection

between client and server is terminated• Server do not have a history list or anything similar, which means

that two consecutive requests from the same client are treated as two different independent requests

• How is this problem solved? i.e. online shops

Computer Net Lab/Praktikum Datenverarbeitung 2 27

Sessions (2)Sessions (2)

• Implementation of a mechanism, which generates (on the server) an unique session-ID at the first request. It will be sent with each further client request to the server.

• Session ID is transmitted– Within the URL, which means each link, used within a

session, includes the session-ID– With use of cookies

max 4 KB text files, which are initiated by the server and sent to the client. They can be used by the client on demand.

Computer Net Lab/Praktikum Datenverarbeitung 2 28

PhpPhp

• PHP is an interpreted language• Platform independent (Windows/UNIX)• Easy Syntax (C-similar)• Easy to integrate in http-Servers (Apache, IIS)• Powerful functions (database access, graphical libraries, etc)• Free Software (no license costs)• Frequently used (as well by public providers)• A lot of ready-to-use modules (forums, web pages, sample scripts)

Computer Net Lab/Praktikum Datenverarbeitung 2 29

PHP: StructurePHP: Structure

• PHP can be embedded in HTML documents or used as pure PHP files.– The PHP code is between two tags:

<?php and

?>

– The file name has in both cases the extension .php

• Each command ends in PHP by a semicolon „;“ or by the PHP end tag.

• Example

Computer Net Lab/Praktikum Datenverarbeitung 2 30

PHP: CommentsPHP: Comments

• Comments in PHP are characterized as follows:

– By the symbol # or // Denotes the following text, until the end of the line as a comment.

– by /* … */ Hereby the enclosed text is denoted as a comment.

Computer Net Lab/Praktikum Datenverarbeitung 2 31

PHP: VariablesPHP: Variables

• PHP uses an automatic data type conversion (i.e. integer to string, etc.).

• Definition:– Variables

$variable_name=“value“

– Arrays$Array_name = array {

value1,value2,…}

Computer Net Lab/Praktikum Datenverarbeitung 2 32

PHP: Control StructuresPHP: Control Structures

IF (condition) { # instructions, if condition is true}

ELSEIF (further conditions) {# instructions, if the first condition was false and this condition is true}

…ELSE {

# instructions, if all conditions are false}

Computer Net Lab/Praktikum Datenverarbeitung 2 33

PHP: LoopsPHP: Loops

• WHILE-loopWHILE (condition) {

# instructions, execute while condition is true}

• FOR-loopFOR (start value; condition; instruction) {

# instructions}

Computer Net Lab/Praktikum Datenverarbeitung 2 34

PHP: FunctionsPHP: Functions

FUNCTION function_name (variables as parameters) {# instructions# optional: RETURN (return value);

}

Computer Net Lab/Praktikum Datenverarbeitung 2 35

PHP: Text OutputPHP: Text Output

• TEXT (HTML-Code) generation with PHP using the command „PRINT“

commands:– PRINT („output text“);– PRINT ($variable);– PRINT ($variable.“output text“);

Computer Net Lab/Praktikum Datenverarbeitung 2 36

PHP: File OperationsPHP: File Operations

• Open file for writing

• Save data in file

• Read data from file

Important: adequate file permissions are required!!!

Computer Net Lab/Praktikum Datenverarbeitung 2 37

PHP: hand over dataPHP: hand over data

• The array $HTTP_POST_VARS contains all the variables handed over via POST method. i.e.: from a form via POST.

• The Array $HTTP_GET_VARS contains all the variables handed over via GET method. i.e.: from a form via GET.

• Example

Computer Net Lab/Praktikum Datenverarbeitung 2 38

Sample ProgramSample Program

Source-Code of the example

Computer Net Lab/Praktikum Datenverarbeitung 2 39

Links about PHP/HTMLLinks about PHP/HTML

• PHP developers homepagehttp://www.php.net

• selfhtml: Excellent document (tutorial) about HTML and morehttp://selfaktuell.teamone.de/