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? 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)
How is CGI Working? A new process on the web server The CGI process reads stdin and environment variables It writes the stdout
Hello World! #! /usr/bin/scriba -c include cgi.bas cgi::Header 200,"text/html" cgi::FinishHeader print """ Hello World! """ stop
Which Environment Variables? Important environment variables (from the http header) –REMOTE_ADDR –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
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
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
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
Getting Parameters #! /usr/bin/scriba -c include cgi.bas cgi::Header 200,"text/html" cgi::FinishHeader print """ """ print cgi::GetParam ("apple") print """ """ stop
Getting Parameters #! /usr/bin/scriba -c include cgi.bas cgi::Header 200,"text/html" cgi::FinishHeader print """ """ print cgi::PostParam ("apple") print """ """ stop
Handling Cookies
File Upload
User Authentication
Thank you for your attention.