CGIs - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

CGIs

Description:

CGI - Common Gateway Interface - a way for web pages to access computer ... CGI Programs mainly used for Form Validation, E-Commerce, Guest Books, etc... CGIs ... – PowerPoint PPT presentation

Number of Views:108
Avg rating:3.0/5.0
Slides: 22
Provided by: PPB9
Category:
Tags: cgis | guestbooks

less

Transcript and Presenter's Notes

Title: CGIs


1
CGIs
  • Server-Side Programming

2
What is a CGI?
  • CGI -gt Common Gateway Interface - a way for web
    pages to access computer programs stored and
    running (key concept!!!) on a web server.
  • PPBHS uses CGIs in Dashboard Page..
  • CGI Programs mainly used for Form Validation,
    E-Commerce, Guest Books, etc...

3
CGIs
  • CGI programs can be written in any programming
    language most written with ASP (Active Server
    Pages - Server-Side JS - Dashboard page - ASP
    only works on MS Web Servers), C, or PERL
  • Two Major Types of Web Servers UNIX (Apache)
    Servers and MS IIS (ASP).

4
CGIs
  • We will first learn PERL since we need for the
    commercial sites we are developing -- -gt onednr
    servers -- -gt OCPO, FVINCENT, LENNYSMARKET, and
    TRIC are hosted -gt UNIX Apache Servers.
  • We need Guest Book CGI for FV Bulletin Board for
    OCPO, etc.

5
PERL
  • PERL - Practical Extraction and Report Language -
    high-level, interpreted lang. - not even designed
    for use with web (more info can be found at
    http//www.perl.com) created in 1986 to easily
    create reports
  • PERL is easily ported from one OS to another
    (because it is interpreted)

6
PERL
  • Has a rep for being a cool lang
  • and for being fun most of you guys know JS so it
    will be fairly easy for you guys to pick up..

7
PERL
  • How is PERL called out from a HTML
  • Heres how you interface via a form
  • ltFORM METHODpost ACTIONhttp//www.lennysmarket.
    com/cgi-bin/bulletin.cgigt
  • Most CGI programs are stored in a directory
    called cgi-bin (perms need to be set for script).

8
PERL Data
  • 3 5 (result is 8)
  • 3 cream (result is 3)
  • ice cream (result 0)
  • ice . cream (result icecream -gt
    concatenation)

9
PERL Data
  • print 3 Main Street (print is the Perl
    function to print back to web page 3 Main
    Street is a constant)
  • variables
  • address3 Main Street
  • print address
  • sum3 5

10
Perl Data
  • Print what is up\ndont know
  • produces what is up
  • dont know
  • print you won prize

11
Steps in Creating a PERL CGI Script
  • Using NotePad/WordPad/Word - simple text editor..
  • Code Perl Program
  • Save as text-only file with extension cgi
  • e.g., nick.cgi.
  • Save in servers CGI-BIN Directory -gt in UNIX
    (Apache Servers run on- exec perm).

12
Creating a PERL Script
  • An Example simple web page with a form form
    asks you to enter your favorite animal and looks
    like this.. -gt web page with form prompting for
    favorite animal

13
Creating a Perl Script
  • The Perl script (CGI) is invoked from a real UNIX
    Apache Server via the Action parameter in the
    HTML Form tag ltform method"POST"
    action"http//www.ppea.info/cgi-bin/form.cgi"
    name"animal-form"gt Which Animal? ltinput
    typetext name"animal" size"20" gt

14
Perl..
  • Action statement in Form action"http//www.ppea.
    info/cgi-bin/form.cgi"
  • Name in Form name"animal-form"
  • Form Static Text and Variable where animal type
    goes Which Animal? ltinput typetext
    name"animal" size"20" gt

15
Perl the script on the Server
  • The Perl Program code for form.cgi
  • The first line of the Perl script
    !/usr/bin/perl wT -gt indicates the path
    on the Server where the Perl interpreter resides
    remember Perl is interpreted and must be run by
    a Perl interpreter it is required..

16
Perl the script on the Server
  • The wT argument on the Perl Path line tells the
    Perl interpreter to warn you of any potential
    script problems (not required)
  • The next line in the script use strict will
    required you to declare your variables (not
    required)

17
Perl the script on the Server
  • Next line use CGI standard tells Perl you
    are writing a CGI script and Perl should bring in
    its CGI Functions .. (this is required!!!)
  • Now we can start writing our code!!!

18
Perl the script on the Server
  • my animal -gt we are defining a variable
    call animal right now theres nothing in it!!
  • animal param(animal) -gt takes the data
    from the field labeled animal in your HTML Form
    which is calling this script..

19
Perl the script on the Server
  • print "Content-type text/html\n\n" -gt this
    line is required before you start sending
    information back to your web page via the Perl
    Print Function -- tells the web page that what
    is being returned is html text.

20
Perl the script on the Server
  • Last Line of Script simply prints/sends the
    animal entered in the web page back to the web
    page
    print "ltPgtShow me the animal..." -gt via the
    Perl print function we send back the information
    contained in the animal variable (a variable is
    a container) notice we have embedded HTML in
    the print string -gt ltPgt -gt everything within

21
Now we need to use Perl to write a Bulletin Board
for OCPO
Write a Comment
User Comments (0)
About PowerShow.com