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 1hehe).
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

hehe).
Rispondi quotando

