Lecture 8

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 11

Web Programming

Lecture 8

1
.htaccess File
Web Programming – Fall 2010

 It provides the ability to customize for


requests to a particular directory
 The directives in the .htaccess file apply to
that directory and all subdirectories
 Why does this start with a dot?
 In several web servers .htaccess is the
default name of directory-level
configuration files.
.htaccess File
Web Programming – Fall 2010

 Common Usage:
 Security
 Customized error responses (e.g. 404)
 Redirects
 CacheControl: control user agent caching to
reduce bandwidth usage, server load etc.
 Most commands in htaccess are meant to be
placed on one line. Turn off word-wrap

3
.htaccess
Web Programming – Fall 2010

 Redirect /olddirectory/oldfile.html
http://yoursite.com/newdirectory/newfile.html
 ErrorDocument 404 /errors/notfound.html
 IndexIgnore *
 IndexIgnore *.gif *.jpg
 order allow,deny

deny from 123.45.6.7


deny from 012.34.5.
allow from all
 www.javascriptkit.com/howto/htaccess.shtml
 http://httpd.apache.org/docs/1.3/howto/htaccess.html

4
CGI
Web Programming – Fall 2010

 Request is collected by the web server


 The corresponding program is called
 Input is sent through QUERY_STRING
 Output from the program is collected by
the Web server
 Headers are added by the Web server
 Output is sent to the client
CGI
Web Programming – Fall 2010

 Can be written in any language


 CGI is notoriously slow
 The program has to load into memory,
execute, and then pass you the document
 Solutions?
 Keep the process in memory at all times !
 Perl, PHP, ASP, Cold Fusion, JSP
Common Gateway Interface
Web Programming – Fall 2010

#include <iostream>
using namespace std;

int main()
{
cout << "Content-Type:text/html"<<endl;
cout << endl;
cout << "<html><body>";
cout << "Hello";
cout << "</body></html>";
return 0;
}
CGI
Web Programming – Fall 2010

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
cout << "Content-Type:text/html"<<endl;
cout << endl;
cout << "<html><body>";
cout << "You queried " << getenv("QUERY_STRING");
cout << "</body></html>";
return 0;
}
Implicit Objects
Web Programming – Fall 2010

 Implicit objects are the objects which are


provided to you by default
 Vary with language
 Take architecture into account
 Almost every language has similar
methods
Request and Response
Web Programming – Fall 2010

 Request : GET and POST data


 Response: display result
 Response may or may not be an HTML
page
 Equivalent objects (almost) exist in all
scripting languages
Navigation on Multiple Pages
Web Programming – Fall 2010

 HTTP is a stateless protocol


 Each request is taken separately
 Users think of the web site as an application

Login Check Mail

Log Out

 How can we store a user’s state?

You might also like