[Tutor] Strange cgi behavior

runsun runsun@bilbo.bio.purdue.edu
Wed, 26 Sep 2001 14:23:04 -0500


I am writing a simple cgi counter in python as a learning exercise:
http://expert.cc.purdue.edu/~runsun/python/counter/simplecounter.cgi

This counter loads countdata.txt (which contains only one
integer), increases that number by one and adds it back.
The code is as following:
--------------------------------------------------------[ Start ]
#!/usr/local/bin/python
print "Content-type: text/html\n\n"
datafile="countdata.txt"

f = open(datafile,"r")
hitlist=f.read()
hitlist = str(int(hitlist)+1)
print hitlist    # <============ the 1st print command
f.close()

f = open(datafile,"w")
f.write(hitlist)
f.close()

print hitlist   # <=========== the 2nd print command
------------------------------------------------------ [ end ] 

When this cgi is execusted by typing simplecounter.cgi
in the command prompt of unix, it returns both print results:

27
27

Another execution does the work : increasing the number 
by one.

28
28

Now, I try to call this cgi from the url address bar of my 
browser. Strange behaviors are :

[1] The result of the 2nd print command never shows up;
[2] A [reload] or [refresh] click to execute the cgi the second
or more times DOES NOT increase the number. This happened
in both IE 5.5 and NS4.03. 

Can someone tell me what's going on ?? thx in advance.

pan

======================================
      ~~ Be like water, be shapeless ~~
Runsun Pan, PhD, Biological Sci. Purdue Univ
Email: runsun@bilbo.bio.purdue.edu
Url : http://bilbo.bio.purdue.edu/~runsun
Tel : 765-496-4186(H), 765-494-4947 (O)
Fax : 775-665-1494 (USA) 094-656-8001 (Taiwan)
        (I can access both through my email)
======================================