Presentation is loading. Please wait.

Presentation is loading. Please wait.

CGI programming Peter Verhás January 2002. What this tutorial is about Introduction to CGI programming Using ScriptBasic –Simple to program –Simple to.

Similar presentations


Presentation on theme: "CGI programming Peter Verhás January 2002. What this tutorial is about Introduction to CGI programming Using ScriptBasic –Simple to program –Simple to."— 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 """ Hello World! """ 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 """ """ i = 0 while IsDefined( Environ(i) ) print i," ",Environ(i),"\n" i = i+1 wend print """ """ stop

8 What is in the QUERY_STRING? Anything that the browser sends A FORM parameters coded –parameter=value pairs joined with & –Space replaced by + –Special characters %XX hexa encoded

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

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

11 Getting Parameters #! /usr/bin/scriba -c include cgi.bas cgi::Header 200,"text/html" cgi::FinishHeader print """ """ print cgi::PostParam ("apple") print """ """ stop

12 Handling Cookies

13 File Upload

14 User Authentication

15 Thank you for your attention.


Download ppt "CGI programming Peter Verhás January 2002. What this tutorial is about Introduction to CGI programming Using ScriptBasic –Simple to program –Simple to."

Similar presentations


Ads by Google