| This page shows the actual source code used on this site. If this is the first CYA source code you've seen you should read this overview first. Did you know you can download all the source code (and the database) of this site? Then get my newsletter to be emailed when I update the source code!
Please spread the word by recommending my site to your friends and colleagues! | This is JScript (server-side JavaScript), not the more common VBScript. More... |
utils/Footer.asp<%
// ============================================
// NOTE: all source code downloaded from CoverYourASP was written by
// James Shaw (unless stated otherwise), and is copyright (c) 2000-2002
// by James Shaw. You can use the code for any purpose, but do not
// publish or distribute the content in any way.
//
// See http://CoverYourASP.com/Legal.asp for up-to-date details.
// ============================================
// ============================================
// output common bottom of page
// ============================================
function Footer ( )
{
Out ( '</tr>' );
Out ( '</table>' );
// I have three separate ways of storing statistics today!
// the first is IncrementArticleCounter, now in utils/Init.asp,
//...and lastly, my attempt to do it all myself by storing
// some statistics in the Stats table in my database
// are we configured to store stats?
if ( bStoreStats )
{
Out ( '<script language="JavaScript" type="text/javascript">' );
Out ( 'var sWidth = \'?width=\' + screen.width;' );
Out ( 'var sRefer = \'&refer=\' + document.referrer;' );
Out ( 'var sURL = \'&url=\' + document.URL;' );
Out ( 'document.write(\'<img src="StatCounter.asp\' + sWidth + sRefer + sURL + \'" width=1 height=1 border=0 alt="">\' );' );
Out ( '</script>' );
// now for those brain dead browsers that don't support
// JavaScript, or who have it turned off
Out ( '<noscript><img src="StatCounter.asp" width=1 height=1 border=0 alt=""></noscript>' );
}
// if using my source code, I'd appreciate an HTML
// comment being output as shown below...
Out ( '\n<!-- portions (c) james@CoverYourASP.com-->\n' );
// client side pull
Out ( '<img src="CountLosses.asp?FootersViewed" width=1 height=1 border=0 alt="">' );
// should we make a plain page for printing?
if ( !bPlainJane )
{
// the second one uses SiteMeter - which provides fancy graphs
// that my other methods don't supply...
// Out ( '<p><!--WEBBOT bot="HTMLMarkup" startspan ALT="Site Meter" -->\n <script type="text/javascript" language="JavaScript">var site="sm2shawthing"</script>\n <script type="text/javascript" language="JavaScript1.2" src="http://sm2.sitemeter.com/js/counter.js?site=sm2shawthing">\n </script>\n <noscript>\n <a href="http://sm2.sitemeter.com/stats.asp?site=sm2shawthing" target="_top">\n <img src="http://sm2.sitemeter.com/meter.asp?site=sm2shawthing" alt="Site Meter" border=0></a>\n </noscript>\n <!-- Copyright (c) 2000 Site Meter -->\n <!--WEBBOT bot="HTMLMarkup" Endspan -->' );
Out ('<script type="text/javascript">\nvar gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));\n</script>\n<script type="text/javascript">var pageTracker = _gat._getTracker("UA-2608412-11");\npageTracker._initData();\npageTracker._trackPageview();\n</script>');
}
Out ( '</body></html>' );
}
%> |
StatCounter.asp<%@ Language=JavaScript %>
<!--#include file = "include/Config.asp"-->
<%
// are we configured to store stats?
if ( !bStoreStats )
Response.End ( );
// get raw data
var sAgent = "" + Request.ServerVariables("HTTP_USER_AGENT");
var sIP = "" + Request.ServerVariables("REMOTE_ADDR");
var sRefer = "" + Request.QueryString( 'refer' );
var sPage = "" + Request.QueryString ( 'url' );
var sWidth = "" + Request.QueryString ( 'width' );
// for pages viewed without JavaScript..
if ( sPage == "undefined" )
sPage = "" + Request.ServerVariables("HTTP_REFERER");
if ( sRefer == "undefined" )
sRefer = "n/a";
if ( sWidth == "undefined" )
sWidth = "n/a";
// dont store any pages that contain my password
// (see http://CoverYourASP.com/Security.asp)
if ( -1 == sPage.indexOf ( sPassword ) &&
// also don't store any pages that start with
// an underscore - they're my private files!
'_' != sPage.charAt ( 0 ) )
{
// for reporting purposes let's strip off all the fluff
// such as http://, any www that appears, etc.
// this will mean our reports will show as few as
// possible duplicate URLs
// make everything lowercase
sAgent = sAgent.toLowerCase ( );
sRefer = sRefer.toLowerCase ( );
sPage = sPage.toLowerCase ( );
// strip off http:// if present
sRefer = RemoveFluff ( sRefer, 'http://' );
sPage = RemoveFluff ( sPage, 'http://' );
// slice off www if present
sRefer = RemoveFluff ( sRefer, 'www.' );
sPage = RemoveFluff ( sPage, 'www.' );
// create database connection
oConnection = Server.CreateObject( 'ADODB.Connection' );
// open connection
oConnection.Open( sConnectionString );
// add record to Stats table
oConnection.Execute ( 'INSERT INTO Stats (Width,Agent,Refer,IP,Page) VALUES (\'' + sWidth + '\',\'' + sAgent + '\',\'' + sRefer + '\',\'' + sIP + '\',\'' + sPage + '\');' );
// close connection
oConnection.Close();
}
// ============================================
// remove sFluff from sURL if present at start of sURL
// ============================================
function RemoveFluff ( sURL, sFluff )
{
if ( 0 == sURL.indexOf ( sFluff ) )
sURL = sURL.slice ( sFluff.length );
return sURL;
}
%> |
Hopefully much of this is self-explanatory. If not, or if you see ways that I can improve the code, please drop me a line. To see the source code for this page, click on the icon below.  | |