1 / 15

CGI programming

CGI programming. Peter Verh á s January 2002. 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. How to setup ScriptBasic web test environment ?.

Télécharger la présentation

CGI programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 cgi::Header 200,"text/html" cgi::FinishHeader print """<HTML> <BODY> Hello World! </BODY> </HTML> """ 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 q=verh%E1s+%2BCGI • PATH_TRANSLATED /home/httpd/cgi-bin/test.bas

  7. Print Out Environment Variables #! /usr/bin/scriba -c include cgi.bas cgi::Header 200,"text/html" cgi::FinishHeader print """<HTML> <BODY> <PRE> """ i = 0 while IsDefined( Environ(i) ) print i," ",Environ(i),"\n" i = i+1 wend print """</PRE> </BODY> </HTML> """ stop

  8. What is in the QUERY_STRING? • Anything that the browser sends • A FORM parameters coded • parameter=valuepairs joined with & • Space replaced by + • Special characters %XXhexa encoded

  9. Print Out QUERY_STRING #! /usr/bin/scriba -c include cgi.bas cgi::Header 200,"text/html" cgi::FinishHeader print """<HTML> <BODY> <PRE> """ print Environ("QUERY_STRING") print """</PRE> </BODY> </HTML> """ stop

  10. Getting Parameters #! /usr/bin/scriba -c include cgi.bas cgi::Header 200,"text/html" cgi::FinishHeader print """<HTML> <BODY> <PRE> """ print cgi::GetParam("apple") print """</PRE> </BODY> </HTML> """ stop

  11. Getting Parameters #! /usr/bin/scriba -c include cgi.bas cgi::Header 200,"text/html" cgi::FinishHeader print """<HTML> <BODY> <PRE> <FORM METHOD="POST"> <INPUT TYPE="TEXT" NAME="apple"> </FORM> """ print cgi::PostParam("apple") print """</PRE> </BODY> </HTML> """ stop

  12. Handling Cookies

  13. File Upload

  14. User Authentication

  15. Thank you for your attention.

More Related