Writing

Feed Software, technology, sysadmin war stories, and more.

Saturday, April 13, 2013

Wrapping our CGI class to do some actual work

Things are moving along with my little series of programming recordings.

In recent days, we created a little test program to chew on QUERY_STRING data to deal with the "?foo=bar&blah=1234" stuff which comes from submitting a form as a GET, or just building a URL that way by hand. Then it was turned into a library and picked up a bunch of tests.

After that, it learned how to deal with percent encoding, which is how you can have things like ampersands and equals signs in your data without messing things up.

Now it's time to finally use this library within a bigger program to get something minimally useful to happen. In today's set of recordings, I write just enough of a wrapper to use the CGI library and grab a specific variable name. Then, depending on what it's set to, I respond with the system time or load average as appropriate. Finally, I show how to write a small HTML page with a form which will let you pick "time" or "load average" and will send it to the new program.

If you ever wondered how to get some dynamic content into a web page, this is the ground floor. Start here and you can work your way up. Soon, there will be POST methods, AJAX calls, and all sorts of other shiny new things which power the web of today.

All are welcome, so feel feel to stop by any time.