HTML/CSS How can I call a CGI script from HTML for my webpage counter?

  • Thread starter Thread starter kingtazie
  • Start date Start date
  • Tags Tags
    Html
AI Thread Summary
It is possible to call a CGI program from an HTML page, primarily through web server configuration. To execute CGI, the server must be set up correctly, often requiring modifications to the Apache httpd.conf file. HTML itself cannot directly call CGI programs, but referencing the CGI program in the HTML, such as using an <img> tag or an <iframe>, is effective. For asynchronous communication, a variant of AJAX can be implemented, allowing dynamic updates without page reloads.Another efficient method is using Server Side Includes (SSI), which requires the host page to have a ".shtml" extension for server parsing. The syntax for including a CGI script is <!--#include virtual="script_name.ext"--> within the HTML. The CGI script must set the MIME type to "text/html" to ensure proper output. However, it is essential to verify that the server is configured to support SSI, as default settings may vary.
kingtazie
Messages
2
Reaction score
0
Hi everyone,

Is it possible to call a CGI program from an HTML page and if so, how is it done? I'm in the process of designing a page and I am working on designing my own counter. Thanks!
 
Technology news on Phys.org
You would need to modify the apache httpd.conf or whatever to add a target or something like that, I'm sure there is information available out there.
 
Since HTML isn't a programming language, you technically don't 'call' CGI programs.

provided your web server is configured to execute CGI, all you need to do is reference the CGI program in some fashion.

for example, a counter program that returns an image might be included in an HTML document using something like
Code:
<img src="/path/to/cgi/counter.cgi" />
 
Yes, do what imabug said.

If you don't want it to be called through an image, make it an <iframe> with no height or width, or set the "display" attribute of the image to "none".

If you want it to communicate asynchronously, you could implement a variant of AJAX, where you change the src of your invisible frame through javascript, dump the .innerHTML attribute into a string, parse it, and change the src of the frame again accordingly.

Simple and effective.
 
If you are under Apache, there's an even easier way to do it: use SSI (Server Side Includes). Most servers now require the host page be named with a ".shtml" (the 's' is for 'server parsed') before parsing a page, but it works like gangbusters. You don't even need to use an image, you an emit the count as pure text.

The syntax looks like this:

<!--#include virtual="script_name.ext"-->

Just put that link in your HTML page (with the .shtml extension), and whatever text the script "script_name.ext" spits out will show in the HTML page as if it had always been there.

The script needs to set the MIME type to "text/html", even though it is just going back to the server for inclusion before being sent to the client. In PERL, you'd do that with

print "Content-Type: text/html\n\n";

Then just print your counter (after reading from a file, updating the file, etc.), and you're done.

NOTE: your server (even if Apache) may not be configured for SSI. I'm pretty sure the default is for SSI to be on, but only applied to .shtml extensions. The default used to be to parse all .html (or .htm) files, but that chews up a lot of processor time parsing pages with no includes.
 
Last edited:
Thanks, Twist!
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.

Similar threads

Replies
2
Views
1K
Replies
3
Views
2K
Replies
8
Views
2K
Replies
5
Views
2K
Replies
5
Views
2K
Replies
3
Views
2K
Replies
4
Views
2K
Back
Top