[Tutor] Hit Counter
Sheila King
sheila@thinkspot.net
Sun, 29 Jul 2001 15:11:11 -0700
Well, I'm not sure this will fix your problem, but first off, I wouldn't
use
pythonw.exe
which is the Windows GUI version of Python
for CGI.
Nor would I use any scripts ending with a .pyw extension.
I would just use python.exe and .py.
Like I said, I'm not sure this will solve the problem, but that was just
something that jumped out at me.
--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/
On Sun, 29 Jul 2001 07:19:06 -0700, "Jon Cosby" <jcosby@wolfenet.com>
wrote about [Tutor] Hit Counter:
:I'd like to write a hit counter for my Web page. As easy as this
:would seem, it's got me stumped. I'm using a hidden form field:
:
:<form action="cgi-bin/counter.pyw">
:<input type="hidden" name="Stats" value="Hit Counter">
:</form>
:
:but I suspect this is where the problem is. Why doesn't the script
:run each time the page loads?
:
:Jon Cosby
:
:-----------------Begin Script--------------------------------------
:
:#! c:\python21\pythonw.exe
:
:print "Content-type: text/html"
:print
:print "<HEAD><TITLE>Python Hit Counter</TITLE></HEAD>"
:print "<BODY>"
:
:
:form = cgi.FieldStorage()
:if form.has_key("Stats") # Hidden field
: InFile = open("count.dat", "r") # Text file with total hits
: Hits = InFile.readline()
: x = int(Hits) + 1
: h = str(x)
:OutFile = open("count.dat", "w")
:OutFile.write(str(x))
:OutFile.close()
:
:
:print "<P><H2>Jon Cosby's web page - Total hits:</H2><br><br> "
:for i in h:
: print "<img src='images/" + i + "silver.gif'>"
:print "</BODY>"
:
:--------------End Script---------------------------------------------
:
:
:
:_______________________________________________
:Tutor maillist - Tutor@python.org
:http://mail.python.org/mailman/listinfo/tutor