Visualizzazione dei risultati da 1 a 7 su 7
  1. #1

    piccolo problema con conta visite in una pagina

    Ho trovato questo script per inserire un semplice contatore di visite su una pagina (che aumenta a ogni refresh)..
    funziona tutto tranne il fatto che il contatore non aumenta
    è perchè conta le visite uniche oppure ho sbagliato qualcosa?
    grazie mille!

    ---
    The code bellow is prepared to be added to your asp pages and it will automatically start counting hits for the page containning it. You may copy the same code to several ASP pages, and the script will count hits for all pages individually.

    You must create a subfolder named "Mycounters" within the cgi-bin directory. The name of the subdirectory may be changed in the script.

    The script will atomatically create one counter (one file within subfolder "Mycounters") per each page containing the script bellow in the first visit. Each time a page is visited the corresponding counter will be open, read the number of hits, increased by one and the new number of hits save to the same counter file.

    The name of individual counters within subfolder "Mycounters" will shown the path to the page visited. For example:
    Hits at /index.asp will be save to /cgi-bin/mycounters/indexasp.txt
    Hits at /mydir1/page1.asp will be save to /cgi-bin/mycounters/mydir1page1asp.txt

    ---
    <%
    file=request.servervariables("PATH_INFO")
    file = replace(file,"/","")
    file = replace(file,".","")
    if file="" then
    file="otros"
    end if
    Set fs = CreateObject("Scripting.FileSystemObject")
    Wfile=server.mappath("\") & "\cgi-bin\Mycounters\" & file & ".txt"
    on error resume next
    Set a = fs.OpenTextFile(Wfile)
    hits = Clng(a.ReadLine)
    hits = hits + 1
    a.close

    if error then
    hits = 1
    end if

    Set a = fs.CreateTextFile(Wfile,True)
    a.WriteLine(hits)
    a.Close
    %>

    Number of hits: <% =hits %>
    ---

  2. #2
    Io uso questo script per il contatore, non ti aumenta però il contatore ad ogni refresh di pagina (come sarebbe logico fare), ma solo se chiudi il browser e poi rientri nel sito:
    codice:
    <%
    Response.Expires = 0
    Set fs = CreateObject("Scripting.FileSystemObject")
    Path = server.mappath("il_tuo_file_contatore.txt")
    Set a = fs.OpenTextFile(path)
    conta = a.ReadLine
    'Controllo gli aggiornamenti di pagina
    If Session("conta") = "" then
      Session("conta") = conta
      'Incremento di 1 il valore presente nel file di testo
      conta = conta + 1
      a.close
      'Scrivo sul file di testo il nuovo valore
      Set a = fs.CreateTextFile(path, True)
      a.WriteLine(conta)
    End If
    a.Close
    
    %>
    Poi nella posizione dove vuoi che sia visualizzato il contatore scrivi:
    codice:
    <%=conta%>

  3. #3
    grazie ancora dirk.
    questo script quindi non conta ogni refresh ma solo se chiudo e riapro la pagina?

  4. #4

  5. #5
    Dimenticavo, il file .txt che contiene il numero delle visite lo devi creare tu vuoto e posizionare nella cartella desiderata (che necessariamente deve avere i permessi in scrittura)

  6. #6
    il problema è che a me serve che aumenti di 1 per ogni refresh..

  7. #7
    Prova così
    codice:
    <%
    Response.Expires = 0
    Set fs = CreateObject("Scripting.FileSystemObject")
    Path = server.mappath("il_tuo_file_contatore.txt")
    Set a = fs.OpenTextFile(path)
    conta = a.ReadLine
      'Incremento di 1 il valore presente nel file di testo
      conta = conta + 1
      a.close
      'Scrivo sul file di testo il nuovo valore
      Set a = fs.CreateTextFile(path, True)
      a.WriteLine(conta)
    a.Close
    
    %>

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.