English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Ok basically i i have a site which displays this code:



People copy and paste this script onto thier websites and my news titles are shown. I was wondering how to put a counter in the small script or seperate that would not only count how many visitors visited peoples sites but told me too somehow. (maybe it could email me the varible number when peoples pages reach over 5000 views? or anything else? maybe with mySQL? Thanx

2006-09-12 08:59:33 · 3 answers · asked by peter s 1 in Computers & Internet Programming & Design

3 answers

There are several options available to you. The simplest one is to add this to your current JavaScript:

document.write ("");

Then you can have img.php masquerade as an image (by, say, outputting a 1x1 transparent GIF image) and log the hit into your database, check the total number of hits and e-mail you if a certain number of page views has been reached.

A better solution (from the pure technology standpoint) would be to give people a new URL to link to. This URL would point to a PHP script that would work like this:

header ('Content-type: text/javascript');
echo << // Put your current JavaScript here...
EOJS;
// Put the counter stuff in PHP here...

Obviously, this would be an inconvenience to people who use your sevice, so you can work around having to have people change the URL they link to. Write the script, test it out, and then put in place a rewrite rule that would make your server run the PHP script instead of serving the JavaScript. To do that, you need mod_rewrite enabled and .htaccess files allowed.

2006-09-14 05:33:21 · answer #1 · answered by NC 7 · 0 0

people don't usually do counters in js.

perhaps you want to search your apache logs for the number of hits on each script?

php is a great language for doing the classic counter program, easy on-the-fly graphics.

2006-09-13 20:48:16 · answer #2 · answered by jake cigar™ is retired 7 · 0 0

here is a good site to look at hope it helps

http://www.phpbuilder.com/snippet/

2006-09-12 16:02:53 · answer #3 · answered by Network Admin 2 · 0 0

fedest.com, questions and answers