BinProlog 5.75 has some built-in facilities which make CGI-programming easy. The following shows a simple Web page access counter.
main:- header, inc(X), write('% '),show_counter(X),write('<p>'),nl, unix(getenv('REMOTE_HOST',Host)), unix(getenv('SERVER_NAME',To)), writeln(['Welcome to',To,'user of',Host,'!']), unix(getenv('QUERY_STRING',ThisProg)), make_cmd([cat,' ',ThisProg],Cmd), writeln(Cmd). fname('/tmp/counter_state.pro'). header:- write('220 ok'),nl, write('content-type: text/html'),nl, nl, write('<TITLE> BinProlog counter demo </TITLE>'),nl. show_counter(X):-write(counter(X)),write('.'),nl. inc(X):-fname(F), ( see_or_fail(F)-> [F]=>counter(X) ; X=0 ), X1 is X+1, tell(F), show_counter(X1), told. writeln(Xs):- forall( member(X,Xs), (write(X),write(' ')) ), write('<p>'),nl.
To install a similar CGI script at your site, put the bp executable in directory cgi-bin, together with the program and call it from a HTML page as follows:
<A HREF= "/cgi-bin/bp?$/<MY ABSOLUTE PATH>/counter.pro"> Click here! </A>
You can try it out by clicking on it at:
http://clement.info.umoncton.ca/~tarau
Look for LogiMOO [23, 1], a more advanced BinProlog based Internet application, now also running directly under Netscape 3.x, at:
http://eve.info.umoncton.ca:8080/~logimoo or http://clement.info.umoncton.ca/~tarau/logimoo