cancel
Showing results for 
Search instead for 
Did you mean: 

DIY hit counter with/without AJAX

decomplexity
Rising Star
Posts: 493
Thanks: 26
Registered: ‎30-07-2007

DIY hit counter with/without AJAX

I need to embed a Home page’s hit count in the text of another page – not as a graphic (neither an off-the-peg counter such as PN's nor one of my own) but as simple HTML text numbers (with the running count held in an SQL database updated by a few lines of PHP).
Since PN uses separate servers for ‘normal webspace’ and CGI, and since for performance reasons I want the Home page to be served from the home pages server, I am going round in circles trying to find an elegant way to do this.
I intended to use ‘onload’ XMLHttpRequests (i.e. AJAX calls) from the Home page and count-display page, but quickly realised that the one from the Home page (at least) would fail because the call will be to the CGI server which is not the Home page’s server, and such cross-site AJAX calls are blocked (with the possible exception of Google's own APIs!)
I was left with the usual hit-counter trick of loading a <img> from a page with a script attached (e.g. img src="http://domain_name.com/php_script_name?page_name "). This could be told to update the count if ‘page_name’ was the home page name, and the returning graphic could then be non-displaying and ignored. But I would still appear to need to serve from the CGI server the page which will actually display the count.
DAK a simple way to serve both the Home page and the display page from the home pages server or a more elegant way to do what I want pls? 
Zen from May 17. PN Business account from 2004 - 2017
1 REPLY 1
glyndev
Grafter
Posts: 620
Registered: ‎31-07-2007

Re: DIY hit counter with/without AJAX

Have a look at www.hotscripts.com there are text and graphical counter scripts in all the main scripting languages. You should be able to find what you are looking for there.