User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 397,602 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,667 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting

Hit counter

Join Date: Jul 2006
Location: Deptford, London
Posts: 943
Reputation: MattEvans has a spectacular aura about MattEvans has a spectacular aura about 
Rep Power: 5
Solved Threads: 47
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Posting Shark

Re: Hit counter

  #6  
Jun 21st, 2007
Well. there are a few methods for getting script output 'into' HTML. But, you have to understand; HTML is not a programming language, it's a document markup language.

One way to get script output into HTML is to generate HTML entirely programmatically. That is, 'print' HTML code directly to a users browser, and the parts that are 'dynamic' can just be printed in with the rest of the HTML. That principle is used quite heavily in languages like PHP; you can write pure HTML, and write blocks of PHP code directly inside the HTML code using 'special markers' to determine the start and end of the PHP. The page is prepared when the user requests it, and sent back different each time. ASP uses the same principle ( embeded code in HTML ). Perl and C++ do the opposite; you output HTML by literally printing it "to the user's browser" as a string.

You can also use something called SHTML ( server-parsed HTML ), it's a very basic system; you write special comments in your HTML code like this: <!--#directive parameter="value"-->, the server looks for those comments, and replaces them by performing the provided directive; an example is: <!--#include virtual="path_to_script"--> : the server will read that when an HTML page is requested; look for the script at "path_to_script" on the server itself, execute it, and place the reply from the script in the data that is sent back to the browser. You need to save the files that do such includes as 'file.shtml' instead of 'file.html', and you need to check whether your server supports it before you rely on it for something..

http://httpd.apache.org/docs/1.3/howto/ssi.html

Both of these methods are very similar, and can actually be used together, i.e. you can write blocks of Perl code that print out 'special' elements ( like a little <div> element containing the number of hits on your page for example =P ) save it somewhere on the server, and then embed the output of that script on every page that's requested using an SHTML include directive. Running the script (by including it) is what increments the counter, so, everytime a page is requested, the counter can be updated.

Both of these methods rely totally on preparation at the server. You have to regenerate the page everytime it's requested. That can affect caching optimizations.. i.e. you CANNOT cache pages that are really dynamic, meaning they have to be downloaded direct from your server everytime they are viewed.

The only method that isn't entirely server-generated is to write a script on the server that does the 'work' and then use a method called AJAX (A)syncronous (J)avascript (A)nd (X)ML to download data from the server and display it within a page when the page has already been downloaded. Erm. I would say, if you want to do that; write the working script on the server and use SHTML to include it first; because it'll teach you the basics, and AJAX is pretty easy if you know Javascript/XML basics already.

http://en.wikipedia.org/wiki/Common_Gateway_Interface
Last edited by MattEvans : Jun 21st, 2007 at 3:35 pm.
If it only works in Internet Explorer; it doesn't work.
Reply With Quote  
All times are GMT -4. The time now is 7:03 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC