Advanced Web Programming - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Advanced Web Programming

Description:

NULL) {PASS=3; printf(' h1 unable to open output file, tell Professor White /h1 ... if (PASS != 1) { printf(' H1 INVALID PASSWORD, See Professor White /H1 ... – PowerPoint PPT presentation

Number of Views:53
Avg rating:3.0/5.0
Slides: 13
Provided by: STE5
Category:

less

Transcript and Presenter's Notes

Title: Advanced Web Programming


1
Advanced Web Programming
  • CGI
  • Imagemaps
  • Frames

2
CGICommon Gateway Interface
  • CGI programming allows us to run arbitrary
    programs at the server, with input provided by a
    FORM which is displayed at the client.
  • Two Types of FORMs, GET and POST
  • GET - parameters sent additions to URL string.
    Each individual parameter separated by
  • POST - Data sent in message body. This is
    slightly more general

3
CGI Processing
  • Server sends form to client
  • Client displays form, and users fills in fields
  • Client sends form info to server
  • Server runs the CGI program named in the ACTION
    section of the FORM..
  • CGI program parses data as input
  • Output of CGI program is sent by the server to
    the client (i.e. it should be HTML)

4
CGI Advantages and Disadvantages
  • Advantages
  • Very general model, easy to do really neat things
    like front end existing applications, databases
    etc.
  • Many toolkits available to do common things
  • Disadvantages
  • All processing is done on server. May overload
    server

5
Writing a CGI Program
  • CGI program needs to
  • Parse form input
  • Process the input
  • Generate html output
  • Example
  • CGI program to collect info and add it to a file
  • Password protected

6
CGI Example
  • Adds links to a file of students in a class
  • Password Protected
  • Steps
  • Parse data (POST form)
  • Check Password
  • Add info (in html format) to end of roster

7
  • include ltstdio.hgt
  • ifndef NO_STDLIB_H
  • include ltstdlib.hgt
  • else
  • char getenv()
  • endif
  • define MAX_ENTRIES 10000
  • typedef struct
  • char name
  • char val
  • entry
  • char makeword(char line, char stop)
  • char fmakeword(FILE f, char stop, int len)
  • char x2c(char what)
  • void unescape_url(char url)

8
void unescape_url(char url) void
plustospace(char str) main(int argc, char
argv) entry entriesMAX_ENTRIES
register int x,m0 int cl int PASS
FILE fp printf("Content-type
text/htmlcc",10,10) if(strcmp(getenv("REQU
EST_METHOD"),"POST")) printf("This
script should be referenced with a METHOD of
POST.\n") printf("If you don't
understand this, see this ") printf("ltA
HREF\"http//www.ncsa.uiuc.edu/SDG/Software/Mosai
c/Docs/fil\ l-out-forms/overview.html\"gtforms
overviewlt/Agt.c",10) exit(1)
if(strcmp(getenv("CONTENT_TYPE"),"application/x-ww
w-form-urlencoded")) printf("This
script can only be used to decode form results.
\n")
9
if(strcmp(getenv("CONTENT_TYPE"),"application/x-ww
w-form-urlencoded")) printf("This
script can only be used to decode form results.
\n") exit(1) cl
atoi(getenv("CONTENT_LENGTH")) PASS 0
for(x0cl (!feof(stdin))x) mx
entriesx.val fmakeword(stdin,'',cl)
plustospace(entriesx.val)
unescape_url(entriesx.val)
entriesx.name makeword(entriesx.val,'')
/ Check here for passwd field Z /
if (entriesx.name'p') if
(strcmp(entriesx.val,"MDSS") 0) PASS 1
if (PASS 1) if ((fp
fopen("/class/nwhite/b3146/roster.html","a"))
NULL) PASS3 printf("lth1gt
unable to open output file, tell Professor
Whitelt/h1gt")
10
NULL) PASS3 printf("lth1gt unable
to open output file, tell Professor
Whitelt/h1gt")
else fprintf(fp,"ltA href\"http//www.stern
.nyu.edu/s\" gt Home Page for s \n \ lt/agt",
entries0.val,entries2.val)
fprintf(fp,"ltpgtlth3gtWhy you might want to visit
the homepage for s ... lt/h3\ gt\n ltpgt",
entries2.val) fprintf(fp,"s
ltpgt",entries3.val) fprintf(fp,"ltpgtlthrgtlthrgtlt
pgt") printf(" Link successfully added
\n") printf("lta href\"http//www.stern.nyu.
edu/nwhite/class/b3146/roster.html\ \"gt
ltbgtClick here to see the updated rosterlt/bgt
lt/agt") if (PASS ! 1)
printf("ltH1gt INVALID PASSWORD, See Professor
White lt/H1gt") -----Emacs addlinkm.c
(C)----Bot--------------------------
11
Frames
  • Frames are new in Netscape 2.0
  • The allow the developer to display multiple
    windows at a time instead of just one. Each
    window will contain a the output from a different
    URL.
  • Very powerful if used with JAVA or JavaScript
    (Now can have separate programs running in each
    Window).

12
Spiders and Robots
  • Since the HTTP protocol is text based, it is
    relatively easy to write programs that cruise
    the WEB collecting information.
  • Examples
  • Indexing programs - continually request URLs,
    index the documents, follow the links of the
    indexed documents and index them etc.
  • Smartmarks - watches URLs and notifies user
    when they change.
Write a Comment
User Comments (0)
About PowerShow.com