CGI programming - PowerPoint PPT Presentation

About This Presentation
Title:

CGI programming

Description:

HTTP_USER_AGENT Mozilla/4.0. HTTP_ACCEPT */* HTTP_CONNECTION Keep ... FORM METHOD='POST' INPUT TYPE='TEXT' NAME='apple' /FORM print cgi::PostParam('apple' ... – PowerPoint PPT presentation

Number of Views:232
Avg rating:3.0/5.0
Slides: 16
Provided by: verh153
Category:

less

Transcript and Presenter's Notes

Title: CGI programming


1
CGI programming
  • Peter Verhás
  • January 2002

2
What this tutorial is about
  • Introduction to CGI programming
  • Using ScriptBasic
  • Simple to program
  • Simple to setup on Linux or any Win
  • Prerequisite understanding web architecture

3
How to setup ScriptBasic web test environment?
  • Install ScriptBasic
  • Edit the configuration file
  • scriba.conf.lsp
  • Compile it using cftc.exe
  • Start sbhttpd
  • Start your browser
  • (Well, this is not true CGI, but does not matter)

4
How is CGI Working?
  • A new process on the web server
  • The CGI process reads stdin and environment
    variables
  • It writes the stdout

5
Hello World!
  • ! /usr/bin/scriba -c
  • include cgi.bas
  • cgiHeader 200,"text/html"
  • cgiFinishHeader
  • print """ltHTMLgt
  • ltBODYgt
  • Hello World!
  • lt/BODYgt
  • lt/HTMLgt
  • """
  • stop

6
Which Environment Variables?
  • Important environment variables (from the http
    header)
  • REMOTE_ADDR 127.0.0.1
  • REQUEST_METHOD GET
  • REMOTE_HOST localhost
  • HTTP_USER_AGENT Mozilla/4.0
  • HTTP_ACCEPT /
  • HTTP_CONNECTION Keep-Alive
  • HTTP_ACCEPT_LANGUAGE hu
  • SCRIPT_NAME test.bas
  • SERVER_NAME localhost
  • SERVER_PORT 80
  • CONTENT_LENGTH 0
  • QUERY_STRING qverhE1s2BCGI
  • PATH_TRANSLATED /home/httpd/cgi-bin/test.bas

7
Print Out Environment Variables
  • ! /usr/bin/scriba -c
  • include cgi.bas
  • cgiHeader 200,"text/html"
  • cgiFinishHeader
  • print """ltHTMLgt
  • ltBODYgt
  • ltPREgt
  • """
  • i 0
  • while IsDefined( Environ(i) )
  • print i," ",Environ(i),"\n"
  • i i1
  • wend
  • print """lt/PREgt
  • lt/BODYgt
  • lt/HTMLgt
  • """
  • stop

8
What is in the QUERY_STRING?
  • Anything that the browser sends
  • A FORM parameters coded
  • parametervalue pairs joined with
  • Space replaced by
  • Special characters XX hexa encoded

9
Print Out QUERY_STRING
  • ! /usr/bin/scriba -c
  • include cgi.bas
  • cgiHeader 200,"text/html"
  • cgiFinishHeader
  • print """ltHTMLgt
  • ltBODYgt
  • ltPREgt
  • """
  • print Environ("QUERY_STRING")
  • print """lt/PREgt
  • lt/BODYgt
  • lt/HTMLgt
  • """
  • stop

10
Getting Parameters
  • ! /usr/bin/scriba -c
  • include cgi.bas
  • cgiHeader 200,"text/html"
  • cgiFinishHeader
  • print """ltHTMLgt
  • ltBODYgt
  • ltPREgt
  • """
  • print cgiGetParam("apple")
  • print """lt/PREgt
  • lt/BODYgt
  • lt/HTMLgt
  • """
  • stop

11
Getting Parameters
  • ! /usr/bin/scriba -c
  • include cgi.bas
  • cgiHeader 200,"text/html"
  • cgiFinishHeader
  • print """ltHTMLgt
  • ltBODYgt
  • ltPREgt
  • ltFORM METHOD"POST"gt
  • ltINPUT TYPE"TEXT" NAME"apple"gt
  • lt/FORMgt
  • """
  • print cgiPostParam("apple")
  • print """lt/PREgt
  • lt/BODYgt
  • lt/HTMLgt
  • """
  • stop

12
Handling Cookies
13
File Upload
14
User Authentication
15
  • Thank you for your attention.
Write a Comment
User Comments (0)
About PowerShow.com