Visualizzazione dei risultati da 1 a 3 su 3

Discussione: contatore con file txt

  1. #1

    contatore con file txt

    ciao...tempo fa ho preso questo codice da non so dove, un contatore semplice per vedere gli accessi totali ad una pagine, l'ho riadattato e funzionava...poi l'ho rivisto ma non mi sembra di aver fatto modifiche sostanziali...fatto sta che ora non va più...

    Codice PHP:
    $countertype "image"// put "text" or "image", choose which counter style you want
    $imagetype ".gif"// if using "image" above, put in the extension with the '.' of the img files. ie: ".gif",".jpg",".png"
    $numofdigits 4// number of digits to show, if number of digits in hits is less than this, tack as many '0's on the front as needed
    $percorso "images/counter/"// percorso per trovare le immagini cart/cart/
    // configuration STOPS here

    error_reporting(0);  // because of some stupid e_notice

    if(!file_exists('../counter/main.txt')){
        
    $fp fopen('../counter/main.txt','w');
        
    fwrite($fp,'1');
    }
    $fp fopen('../counter/main.txt','r');
    $counta fgets($fp);
    $host $HTTP_SERVER_VARS["HTTP_HOST"];

    if(
    $_SESSION["counter"] == "isset"){
    }else{
        
    $_SESSION["counter"] = "isset";
        if(!
    strstr($HTTP_SERVER_VARS['HTTP_REFERER'], $host)) {
            
    $counta++;
            
    $fp fopen('../counter/main.txt','w');
            
    fwrite($fp,$counta);
        }
    }


    $digits = array();
    $digitlen strlen($counta);

    // this fills in the 0's before the number of hits, according to $numofdigits
    $zerostofill $numofdigits $digitlen;
    if (
    $zerostofill 0) {
        
    $countc 1;
        while (
    $countc <= $zerostofill) {
            
    $countd .= 0;
            
    $countc++;
        }
        
    $countc $countd.$counta;
    } else 
    $countc $counta;

    if (
    $countertype != "image") echo $countc//checks if the counter type is set to image, otherwise just print out the num of hits
    else {
        
    $countb 0;
        
        
    // and this finds the number of digits, and assigns each digit to part of an array, then gets the corresponding array[num], and prints it

        
    while ($countb strlen($countc)){
            
    $digits[$countb] = substr($countc,$countb,'1');
            
    $countb++;
        }
        
    $countb 0;
        while (
    $countb strlen($countc)) {
            echo 
    '[img]' $percorso  $digits[$countb] . $imagetype '[/img]';
             
    $countb++;
        }


  2. #2
    nessuno che può darmi una mano?!?

  3. #3
    mi viene più semplice riscriverlo

    codice:
    <?
    $countertype = "image"; // put "text" or "image", choose which counter style you want
    $imagetype = ".gif"; // if using "image" above, put in the extension with the '.' of the img files. ie: ".gif",".jpg",".png"
    $numofdigits = 4; // number of digits to show, if number of digits in hits is less than this, tack as many '0's on the front as needed
    $percorso = "images/counter/"; // percorso per trovare le immagini cart/cart/
    // configuration STOPS here
    
    $file_counter = '../counter/main.txt';
    session_start();
    
    if(!file_exists($file_counter)) {
        // crea il file contatore se non esiste
        touch($file_counter);
    }
    
    if(!isset($_SESSION['counter']) || (isset($_SESSION['counter']) && $_SESSION['counter'] != 'isset')) { // se la sessione non esiste
         $_SESSION['counter'] = 'isset'; // crea la sessione
         $visits = intval(trim(file_get_contents($file_counter))); // legge il contatore
         ++$visits; // aggiorna il contatore
         $fp = fopen($file_counter, 'w'); // aggiorna il file contatore
         fputs($fp, $visits);
         fclose($fp);
    } else { // se esiste la sessione
         $visits = intval(trim(file_get_contents($file_counter))); // legge il contatore
    }
    
    $visits = sprintf("%0{$numofdigits}d", $visits); // formatta il contatore con gli zero
    
    if($countertype == 'image') { // se il formato è immagine
       $img_output = '';
       $len = strlen($visits);
       for($x = 0; $x < $len; ++$x) {
           $img_output .= "<img src=\"{$percorso}{$visits[$x]}{$imagetype}\">"; // crea i tag immagine
       }
       $visits = $img_output;
    }
    
    echo $visits; // stampa il contatore
    ?>
    E' la mia opinione ed io la condivido
    Non condivido la tua idea ma darei la vita perché tu la possa esprimere (Voltaire)
    Scrivi sul muro

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 © 2024 vBulletin Solutions, Inc. All rights reserved.