Today we started with this exercise: Write a CGI program in Python that can update a counter at the user's request. The counter goes up and down by one. The basic outline of the interface is like this: +---------------------------------------+ | The counter is now: .......... | | | | Press [here] to go up. | | | | Press [here] to go down. | +---------------------------------------+ The first [here] is a link, the second is a button. Here's what we developed in class: !/usr/bin/python import cgi print "Content-type: text/html\n\n" (counter, message, action) = ("", "", "") d = cgi.FieldStorage() if d.has_key("counter"): counter = d["counter"].value if d.has_key("message"): message = d["message"].value if d.has_key("action"): action = d["action"].value if message: if action == "up": counter = str(int(counter) + 1) else: counter = str(int(counter) - 1) message = "Your new counter value is: " + counter else: counter = 0 message = "Welcome, your counter is: " + str(counter) print """
%s

Press here to go up.

Press to go down.

""" % (message, counter, message, counter, message) Introduction to PHP We briefly stated how PHP works, then we converted this program to PHP:

Press here to go up.

Press to go down.