Web Programming Week 1 Old Dominion University Department of Computer Science CS 418/518 Fall 2007 Michael L. Nelson 8/27/07
Goals We will learn to work in the LAMP environment:
No MS Environments!
Goals Demonstrate LAMP proficiency with a semester long project based on a bulletin board system. Some examples: – – –
Prerequisites I assume you know: –how to program in some (imperative) language –basic Internet/WWW concepts –basic HTML –basic relational database concepts
Who Should Take This Class? This class will cover breadth, not depth If you want to learn more about: –System administration CS 454/554 Network Management –HTTP CS 495/595 Web Server Design –databases CS 450/550 Database Concepts CS 419/519 Internet Databases and many others…. –Java CS 695 Java & XML
Administrivia This is a programming class! –I assume you know how to program –your grade will be determined solely on your server’s performance on 4 different checkpoints through the semester You will work in teams of 1 or 2 –(grad + undergrad teams are possible) Pick teams wisely –teams will exist by mutual consent only –at any time, teams can split up, but no new teams will be formed after the first assignment is due –ex-team members will have access to their shared code base
Administrivia 2 Important URLs – – Class homepage: –Readings are listed under the day they are expected to be completed –assignments are listed under the day they will be demoed in class –each group will give a 3-4 minute status report the week before an assignment is due! All development will be done on a shared linux machine –mln-web.cs.odu.edu
Grading 4 programs, 23 points each –20 points for functional requirements –3 points voted on by other groups for aesthetic appeal 8 remaining points come from each group asking or answering 8 technical questions about the assignments on the list –no points for duplicate questions or answers!
HTTP Operation Client Origin Server request = (method, URI, version, “MIME-like” message) response = (version, success/error code, “MIME-like” message)
GET AIHT:~/Desktop/cs595-s06 mln$ telnet 80 | tee 1-1.out Trying Connected to xenon.cs.odu.edu. Escape character is '^]'. GET /~mln/index.html HTTP/1.1 Connection: close Host: HTTP/ OK Date: Mon, 09 Jan :07:04 GMT Server: Apache/ (Unix) ApacheJServ/1.1.2 PHP/4.3.4 Last-Modified: Sun, 29 May :46:53 GMT ETag: "1c52-14ed-42992d1d" Accept-Ranges: bytes Content-Length: 5357 Connection: close Content-Type: text/html Home Page for Michael L. Nelson <!-- [lots of html deleted] Connection closed by foreign host. Request (ends w/ CRLF) Response
HEAD AIHT:~/Desktop/cs595-s06 mln$ telnet 80 | tee 1-2.out Trying Connected to xenon.cs.odu.edu. Escape character is '^]'. HEAD /~mln/index.html HTTP/1.1 Connection: close Host: HTTP/ OK Date: Mon, 09 Jan :14:39 GMT Server: Apache/ (Unix) ApacheJServ/1.1.2 PHP/4.3.4 Last-Modified: Sun, 29 May :46:53 GMT ETag: "1c52-14ed-42992d1d" Accept-Ranges: bytes Content-Length: 5357 Connection: close Content-Type: text/html Connection closed by foreign host.
POST Typically the result of HTML “Forms” – html40/interact/forms.html#h http:// html40/interact/forms.html#h Two types of values in the client’s “Content- type” request header: –application/x-www-form-urlencoded (original & default) –multipart/form-data introduced in RFC-1867; allows file upload –
HTML Examples <FORM action=" enctype="multipart/form-data" method="post"> What is your name? What files are you sending? <FORM action=" enctype= "application/x-www-form-urlencoded" method="post"> What is your name? based on examples from:
application/x-www-form-urlencoded POST /~mln/foo.cgi HTTP/1.1 Host: Connection: close Referer: User-Agent: CS 595-s06 Automatic Testing Program Content-type: application/x-www-form-urlencoded Content-Length: 134 action=restore&manufacturer=ford&model=fairlane+500XL &year=1966&status=modified&engine=427+sideoiler &transmission=4+speed+toploader functionally the same as (modulo a possible 414 response): GET /~mln/foo.cgi?action=restore&manufacturer=ford&model=fairlane+500XL &year=1966&status=modified&engine=427+sideoiler&transmission=4+speed+toploader HTTP/1.1 Host: Connection: close Referer: User-Agent: CS 595-s06 Automatic Testing Program
multipart/form-data (with file upload) POST /~mln/foo.cgi HTTP/1.1 Host: Connection: close Referer: User-Agent: CS 595-s06 Automatic Testing Program Content-type: multipart/form-data; boundary= xKhTmLbOuNdArY Content-Length: xKhTmLbOuNdArY Content-Disposition: form-data; name=”action" restore xKhTmLbOuNdArY Content-Disposition: form-data; name=”manufacturer" ford xKhTmLbOuNdArY Content-Disposition: form-data; name=”model" fairlane 500xl xKhTmLbOuNdArY Content-Disposition: form-data; name=”year" xKhTmLbOuNdArY Content-Disposition: form-data; name=”picture"; filename="fairlane.txt" Content-Type: text/plain ______________ // \\ // \\ | __ __ | |--/ \ / \---| \__/ \__/ xKhTmLbOuNdArY-- note the “--” to indicate the end
Response Codes - 1xx: Informational - Request received, continuing process - 2xx: Success - The action was successfully received, understood, and accepted - 3xx: Redirection - Further action must be taken in order to complete the request - 4xx: Client Error - The request contains bad syntax or cannot be fulfilled - 5xx: Server Error - The server failed to fulfill an apparently valid request from section of RFC 2616
But Few Web Resources Are Static Files… Client Origin Server GET /foo HTTP/1.1 HTTP/ OK foo HTML, PDF, etc. foo PHP, ASP, JSP foo Java, Javascript
Server Side Processing Mnemonic HTML code PHP CODE html “Traditional” CGI (e.g. Perl)
Let’s Look at Some PHP
To Do for Next Time… Subscribe to the class list Log in to: mln-web.cs.odu.edu (I will send to the class list when the accounts are ready) –uid/passwds same as *.cs.odu.edu machines don’t have a *.cs.odu.edu acct? get one: –MySQL login == linux login; passwd = (to be determined) Start reading & practicing in your own public_html directory on the cs machines me your group info! If you’re not in a group by 11:59 PM Sept 10, you’re working alone.