Hello again, vicky2k-ga,
There are two ways to do what you ask. The first is the simplest by
far; but there's a chance that it will slightly undercount visitors
because of possible caching. The second expands slightly on the first
and won't have a caching problem.
METHOD ONE: simply embed this tag in your page:
<img src="http://address.of.your.server:45450/dummy.gif">
This will cause the client's browser to connect to your server on port
45450, in order to request an image file.
Now, to prevent a "broken image" icon from appearing afterwards, your
program just needs to respond with a valid HTTP response header and a
valid image file -- which should be a 1x1 completely transparent GIF
image, just a few bytes in all. Very easy to do.
The header you output must look like this:
HTTP/1.0 200 OK
Content-type: image/gif
Followed by TWO newlines, then the contents of the GIF image file.
You can pick up the completely transparent GIF image file you need here:
Pixel Ruler and Spacer - Useful Tools for Web Design
http://www.geocities.com/SoHo/Studios/2165/ruler.html
METHOD TWO: the same as method one, except that you use Javascript to
ensure that the URL in the img tag is always unique, and therefore
never found in the browser's cache, AOL's cache, or any other
interfering cache that might prevent the connection from happening.
Use the following HTML:
<script>
var date = new Date();
document.write("<img width=1 height=1
src=\"http://address.of.your.server:45450/dummy.gif?");
document.write(date.getTime());
document.write("\">");
var date = new Date();
</script>
<noscript>
<img src="http://address.of.your.server:45450/dummy.gif">
</noscript>
Just as with method one, your server on port 45450 must respond with a
simple but correct HTTP response and a tiny image file, as explained
above.
If the browser has Javascript enabled, then Javascript is used to add
the current time in seconds to the URL, preventing caching from taking
place. If Javascript is disabled, the tag between <noscript> and
</noscript> is still used, ensuring that the best possible count is
obtained under any set of circumstances.
I enjoyed answering this question for you. Please feel free to ask
clarifying questions if anything is unclear. Thank you! |
Clarification of Answer by
majortom-ga
on
09 Mar 2004 15:46 PST
Hello again, vicky2k-ga,
I have a solution to that problem for you. However, it is worth
mentioning that the VB.NET code to send that image would not be
complex. A 1x1 transparent GIF
is usually only about 48 bytes. This is something you can easily put in an
array of bytes right in the code if you don't want to access a file.
But if you're sure you don't want to do that, you can solve the problem this way:
<script>
var date = new Date();
var image = new Image();
image.src = "http://address.of.your.server:45450/dummy.gif?" + date.getTime();
</script>
This will work regardless of whether an actual valid image comes back
from your application or not, and no "broken image" icon will appear.
It works because the image is being "preloaded" but not actually
placed in the page, so the fact that the loading ultimately fails
doesn't interfere with the appearance of the page.
This doesn't work if Javascript is turned off in the browser, but most
users do have it turned on, and your original question did call for a
scripting solution, so this should be sufficient for your needs. If
you decide you really want to also count the users who have Javascript
turned off, you can always look into sending a valid HTTP response
with an image, as described in my original answer.
Thanks for the opportunity to solve this interesting problem.
|