Im looking for a free visitors today script, I have a users online and the project requires a visitors today too To display something like: 1019 Visitors today Preferably a flat file script if possible, but mysql would be ok too Thanks for your help!
You want the script to count today's visitors (unique or views?) and at the end of the day the counter will start over from zero?
script source from: http://3w.ezer.com/asp/counter/counter_script.asp#example_code Description: base on IP, no duplicate IP each day counter Table1 id IP date (time) visitors hits 1 *.*.*.77 11/9/2007 1 2 2 *.*.*.99 11/9/2007 1 3 Example Code: <% '--------------the script created by ezer.com --------- IP=request.servervariables("remote_addr") Today=date oneVisitor=1 oneHit=1 '---------- no duplicate IP each day --------------- Set rs1 = GetSQLserverRecordset (con, "select * from TB1 where IP='"&IP&"' and date='"&Today&"' ") if rs1.eof then ' can not find one rs1.AddNew rs1("IP")=IP rs1("date")=Today rs1("visitors")=oneVisitor rs1("hits")=oneHit rs1.Update else rs1("hits")=rs1("hits")+1 rs1.Update end if '-------- Sum Total of a field ---------------------- SQL2="SELECT SUM(visitors) AS sumVisitors from TB1 where IP='"&IP&"' and date='"&Today&"' " Set RS2 = Server.CreateObject("ADODB.Recordset") RS2.Open SQL2,con sumVisitors=rs2("sumVisitors") SQL3="SELECT SUM(hits) AS sumHits from TB1 where IP='"&IP&"' and date='"&Today&"' " Set RS3 = Server.CreateObject("ADODB.Recordset") RS3.Open SQL3,con sumVisitors=rs3("sumhits") rs1.close rs2.close rs3.close %> Today is : <%=date%><br> Today Total visitors: <%=sumVisitors%> <br> Today Total hits : <%=sumHits%> Example Result: Today is : 11/9/2007 Today Total visitors: 2 Today Total hits : 5
hmmjust get "Microsoft VBScript runtime error '800a000d' Type mismatch: 'GetSQLserverRecordset' " Thanks anyway
1. some adjustment <% '-------- Sum Total of a field ---------------------- SQL2="SELECT SUM(visitors) AS sumVisitors from TB1 where date='"&Today&"' " Set RS2 = Server.CreateObject("ADODB.Recordset") RS2.Open SQL2,con sumVisitors=rs2("sumVisitors") SQL3="SELECT SUM(hits) AS sumHits from TB1 where date='"&Today&"' " Set RS3 = Server.CreateObject("ADODB.Recordset") RS3.Open SQL3,con sumHits=rs3("sumHits") rs1.close rs2.close rs3.close %> 2. Type mismatch: 'GetSQLserverRecordset' " if you get this: "Microsoft VBScript runtime error '800a000d' Type mismatch: 'GetSQLserverRecordset' " this means: no define for 'GetSQLserverRecordset' that is why [ mismatch ] you may add a function for this and you may name it whatever name you want Function GetSQLServerRecordset( con, source ) Dim rs Set rs = Server.CreateObject("ADODB.Recordset") rs.Open source, con, 2, 2 Set GetSQLServerRecordset = rs End Function
try this code that i made <% on error resume next SET MyFileObject = Server.CreateObject("Scripting.FileSystemObject") SET MyCouNtFile = MyFileObject.OpenTextFile(Server.MapPath("day.txt")) if int(day(now())) <> int(MyCountFile.Readline) then SET MyCouNtFile = MyFileObject.CreateTextFile(Server.MapPath("day.txt")) MyCountFile.WriteLine day(now()) MyCountFile.Close SET MyCouNtFile = Nothing SET MyCouNtFile = MyFileObject.CreateTextFile(Server.MapPath("count.txt")) MyCountFile.WriteLine 1 MyCountFile.Close SET MyCouNtFile = Nothing end if MyCountFile.close SET MyCouNtFile = MyFileObject.OpenTextFile(Server.MapPath("count.txt")) Application.Lock() IF NOT MyCountFile.AtEndOfStream THEN Visitor = MyCountFile.Readline idx=Len(Visitor) For j=1 to idx Jx=Mid(Visitor,j,1) display=display & Jx Next End if MyCountFile.close SET MyCouNtFile = MyFileObject.CreateTextFile(Server.MapPath("count.txt")) MyCountFile.WriteLine Visitor+1 Application.UnLock() MyCountFile.Close SET MyCouNtFile = Nothing SET MyFileObject = Nothing Response.Write "TodayVisitor : " & display %> Code (markup):
You can use the following code for a no DB or FILE counter, just put this code into global.asa, if you do not have this file, create it in the main application directory. <script language=JavaScript runat=server> // ============================================ // this function is called when the first user visits the page after the server // has been rebooted. also called when this file is changed. // ============================================ function Application_OnStart ( ) { // you dont need to lock the Application object // in this function - but remember to do it elsewhere... // Application.Lock ( ); // number of users currently on the site Application ( 'ActiveUsers' ) = 0; // number of users on the site today Application ( 'UsersToday' ) = 0; // number of pages viewed today Application ( 'PagesToday' ) = 0; // has the count been restarted today? Application ( 'NewToday' ) = 1; // number of headers viewed ever Application ( 'HeadersViewed' ) = 0; // number of footers viewed ever Application ( 'FootersViewed' ) = 0; // initialize new stuff in utils/Init.asp Application ( 'BrandNewDay' ) = 1; // a list of IP addresses that have clicked an ad Application ( 'ClickFromIP' ) = ''; // counters for rotating banners Application ( 'CurrentTopBanner' ) = 0; Application ( 'CurrentSideBanner' ) = 0; Application ( 'CurrentAffiliate' ) = 0; // remember todays date var d = new Date; Application ( 'Today' ) = d.getDate ( ); // Application.Unlock ( ); } // ============================================ // this function is called when the server shuts down // ============================================ function Application_OnEnd ( ) { } // ============================================ // this function gets called whenever a new user visits the site. note that // session variables require the client browser to accept cookies // ============================================ function Session_OnStart ( ) { // you must lock the global Application object // when writing to it - ok to read without lock Application.Lock ( ); // one more active user Application ( 'ActiveUsers' )++; // is it a new day? var d = new Date; var nDate = d.getDate ( ); if ( Application ( 'Today' ) == nDate ) { // same day, so increment users today Application ( 'UsersToday' )++; } else { // new day, so restart count Application ( 'Today' ) = nDate; Application ( 'UsersToday' ) = 1; Application ( 'PagesToday' ) = 1; Application ( 'BrandNewDay' ) = 1; // and say I havent restarted today Application ( 'NewToday' ) = 0; } Application.Unlock ( ); } // ============================================ // this function gets called after a user session times out - by default // after 20 minutes. or you can call Session.Abandon ( ) // ============================================ function Session_OnEnd ( ) { // you must lock the global Application object // when writing to it - ok to read without lock Application.Lock ( ); // one less active user Application ( 'ActiveUsers' )--; Application.Unlock ( ); } </script> Code (markup):
why dont using google analytics? its very good! i use a service like it in my site http://www.e-msjed.com