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

    [PHP] problema con script contatore di visite

    Salve a tutti,
    spiego brevemente il mio piccolo problemino...
    ho sviluppato un counter script (contatore) che mi salva qualche dato interessante sui visitatori del mio sito.
    fin qui tutto bene... lo scirpt funziona come voglio io...
    Ora il problema. Spesso c'è la necessità (come nel mio caso) di cominciare a conteggiare le visite da un numero ben specifico (che tra l'altro non sta bene cominciare a contare da 1 hehe).
    Vi posto il codice, vedete se riuscite a capirci qualcosa... visto che non è che sia troppo commentato
    Vi ringrazio!

    codice:
    session_start();
    
    $start_value = 2700; //the counter will start to count from this value
    
    function db_conn($url,$user,$pass,$dbname) {
      mysql_connect($url,$user,$pass) or die(mysql_error());
      mysql_select_db($dbname) or die(mysql_error());
    }
    
    function counter() {
     if(!isset($_SESSION['log']) || $_SESSION['log'] != true) {
    	db_conn("localhost","****","******","*****");
    	$numrows = mysql_num_rows(mysql_query("SELECT * FROM counter"));
    	 ($numrows<1) ? $numrows=0 : $numrows--;  //this prevents a mysql server error for the first time the script will be
    											  //run. (if no records are detected $numrows will be -1, namely an invalid value)
    	$query = mysql_query("SELECT * FROM counter LIMIT ".($numrows).", 1");
    	$result = mysql_fetch_row($query);
    	 if($numrows!=0 || !empty($numrows))
    	 	$current_count = $result[1];
    	 else
    	 	$current_count = $result[1] + $start_value;	
    		
    	$query = mysql_query("INSERT INTO counter VALUES('','".(++$current_count)."','".$_SERVER['HTTP_USER_AGENT']."','".$_SERVER['HTTP_REFERER']."','".$_SERVER['PHP_SELF']."','".$_SERVER['REMOTE_ADDR']."','".session_id()."','".date("Y.m.d")."','".date("H:i")."');");
    	$_SESSION['hits'] = $current_count;
    	$_SESSION['log'] = true;
        } // end if
    return $_SESSION['hits'];
    } //end counter function
    If today was perfect, there would be no need for tomorrow...
    Live as you want, the wildest way you can, till you're alive!!

  2. #2
    up
    If today was perfect, there would be no need for tomorrow...
    Live as you want, the wildest way you can, till you're alive!!

  3. #3
    non c'è nessuno che mi può aiutare?
    If today was perfect, there would be no need for tomorrow...
    Live as you want, the wildest way you can, till you're alive!!

  4. #4
    la soluzione è a dir poco stupidissima

    basta che da qualche parte salvi la variabile...e prima di stampare a video fai una semplicissima somma

    cmq...xche non sta bene partire da zero?
    deve servire anche a te stesso e agli altri per capire qual'è la qualità delle informazioni che inserisci nel sito
    il sito deve crescere pian piano...

    prima di correre si deve camminare, ma prima ancora a mettersi in piedi ^^
    The fastest Redis alternative ... cachegrand! https://github.com/danielealbano/cachegrand

  5. #5

    :(

    ma la variabile l'ho dichiarata... e la somma la fa!
    scusa la mia ignoranza ma sono un novizio
    mi puoi fare un esempio?
    If today was perfect, there would be no need for tomorrow...
    Live as you want, the wildest way you can, till you're alive!!

  6. #6
    ah per quanto riguarda partire da 0... il sito non è per me, e il cliente ha voluto così... e comunque visto che sto imparando è anche un po di trainig... hehhe
    If today was perfect, there would be no need for tomorrow...
    Live as you want, the wildest way you can, till you're alive!!

  7. #7
    ok ho trovato ora funziona....
    ma se dichiaro variabili al di fuori delle funzioni non posso utilizzarle all'interno di esse (come in C per esempio)?!?
    avevo dichiarato la variabile al di fuori della funzione, appunto e per questo non la riconosceva all'interno.
    mah
    avbbeh comunque problema risolto
    grazie
    If today was perfect, there would be no need for tomorrow...
    Live as you want, the wildest way you can, till you're alive!!

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.