Re: CGI?
Re: CGI?
- Subject: Re: CGI?
- From: Sander Tekelenburg <email@hidden>
- Date: Fri, 13 Apr 2001 18:57:47 +0200
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
At 17:12 -0700 UTC, on 12/04/2001, Michelle Steiner wrote:
>
On 4/12/01 3:31 PM, cris <email@hidden> wrote:
>
>
>Open the standard additions and look at the 'handle CGI request' under
>
>'Internet suite'.
>
>
>
>If you just want to have a counter you can ignore all the optional
>
>parameters and just put your script code into the handler.
>
>
Like this:
>
>
on handle CGI request
>
set FileID to open for access file "dora:counter" with write permission
>
if (get eof FileID) is not 0 then
>
set NumberOfAccess to read FileID
>
else
>
set NumberOfAccess to 0
>
end if
>
set NumberOfAccess to NumberOfAccess + 1
>
set eof FileID to 0
>
write (NumberOfAccess as text) to FileID
>
close access FileID
>
return NumberOfAccess
>
end handle CGI request
>
>
Where does it get saved, though? In a script file, in the html page? If
>
the former, how do I access it from the page? if the latter, where in
>
the page?
It's up to you to decide what you want to do with the returned value of your
"NumberOfAccess" variable. If you want it displayed as text within the
webpage, you can choose to have another handler read the HTML document and
insert "NumberOfAccess" in the right spot. You probably know how tricky and
slow that can be. I'd probably use Leonard Rosenthol's RegEx Commands OSAX
for this.
You could also create a range of images of the numbers 0 thru 9, and use the
value of "NumberOfAccess" to decide which image should be displayed in your
HTML page. The advantage of this is that you could do that by simply copying
the image to a location and rename it - so you won't have to read the HTML
file, find the location where you want to insert/change something.
Probably the easiest would be to use yet another alternative, namely to use a
simplified form of server side include: just have your cgi create a
'throw-away' HTML file that, within <BODY></BODY> only contains your
counter's value, and have that file included through <IFRAME></IFRAME> in
your main HTML document. (Not every browser out there supports <IFRAME>
though.)
>
>At the end of the handler you have to return back something to the
>
>webserver (which will pass it to the browser). You need to specify the type
>
>of
>
>response in the header. In this case it will be a '200 OK' which looks so:
>
>
>
>property CRLF : (ASCII character 13) & (ASCII character 10)
>
>property http_OK_header : "HTTP/1.0 200 OK" & CRLF & "Server: MacHTTP" &
>
>CRLF & "MIME-Version: 1.0" & CRLF & "Content-type: text/html" & CRLF & CRLF
>
>
This goes in the header of the HTML page?
No. This is HTTP, not HTML.
A "user-agent" (usually a webbrowser, but can also be a searchengine's
spider) sends your server a request. A server doesn't simply answer that
request by sending the right document. It first says "OK, I've got that file,
here it comes" (or it says , "I don't have that file" as in "404 not
found"). right before sending the file, the server must also provide some
META information with it. For instance, it must tell the browser what kind of
file it is sending. That's what the :"Content-Type" header is about. (Note
that the above example is invalid - you must not only say that it is
"text/html", but also provide char set information - see the HTML 4.01
specs.)
You might want to have a look at the HTTP specs. You might also want to use
iCab's logging capability to have an example of "HTTP - talk". (In iCab's
prefs, go to Network->Connections/Log->Log file and enable loggging. Then
visit a view sites, then open the log and read it.)
>
What would I use for "server:
>
MacHTTP" for personal web sharing instead of the MacHTTP server?
Whatever string you want your server identify itself as - you have it
identify itself as "Michelle's server" if you want ;) (But providing the real
name/version of the server is probably nicer to your visitors.)
>
>The full response would then look so:
>
>return http_OK_header & myStaticPagePart1 & myCounterValue &
>
>myStaticPagePart2
>
>
Where does this go?
This is what your cgi should hand back to your server (for it to send to the
remote client). If I understand the dictionary correctly, it is just a matter
of making sure this is the returned value of your CGI (instead of just the
counter, as you have in your script above).
HTH
-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <
http://www.pgp.com>
iQA/AwUBOtcv9+sywKfXgqKdEQLSWgCg4XT8nH3LdK0sHkYtu4352Rwe/+MAn1Q3
+PKzTd9D2rGyaGFdNWh9MiVh
=/sJK
-----END PGP SIGNATURE-----
--
Sander Tekelenburg, <
http://www.euronet.nl/~tekelenb/>
Mac user: "Macs only have 40 viruses, tops!"
PC user: "SEE! Not even the virus writers support Macs!"
References: | |
| >Re: CGI? (From: Michelle Steiner <email@hidden>) |