Licznik odwiedzin

~robert

No avatar

2006-07-04 11:08

Chciałbym dodać licznik odwiedzin w php. Korzystam z wersji QC 1.3. Wstawianie kodu do index.php nie działa. Co robię źle? Proszę o wskazówki i pomoc

robert

treewood (OpenSolution)

Avatar: treewood

2006-07-04 13:58

robert - a moze statystyki dostarczane przez providerow wystarcza? pokaz kawalek kodu tego licznika to zobaczymy co sie da zrobic

~robert

No avatar

2006-07-04 14:24

W miedzyczasie probowałem to dodac do page.tpl do stopki strony, ale tez nici... brakuje mi wiedzy, prosze o pomoc... poniżej kod który chce wstawic:


<?php // opens the php document

$file = "count.txt"; // sets the file where the count will be located
$counter = file("$file"); // makes the script read the text file
$r = $counter[0]; // sets $r to the number in the counter file
if (strlen($r) == 0) {$r=0;} $r=$r+1; // if the string length of the count is zero it will add one
$e = fopen("$file", "w"); // opens the file and sees if it is writable
fwrite($e, $counter=""); // erases the count in the file
fwrite($e, $r); // writes the new count to the file
fclose($e); // closes the file
echo("$r"); // shows the file
?>
</body>
</html>

robert

treewood (OpenSolution)

Avatar: treewood

2006-07-04 15:01

robert - korzystajac ze skryptu zrob dosc fajny myk.
1. edytuj core/other.php i dodaj ponizszy kod:

function counter( ){
  
$sFile 'db/counter.txt';
  
$aFile file$sFile );
  
$sData $aFile[0];
  if( 
strlen$sData ) == ){
    
$sData 0;
  }
  
$sData++;
  
$rFile fopen$sFile 'w' );
  
fwrite$rFile$sData );
  
fclose$rFile );
  return 
$sData;
// end function counter

2. utworz plik counter.txt w katalogu db/ i nadaj mu prawa chmod 777
3. edytuj plik index.php i w 3 linii od konca zaraz przed funkcja echo ... dodaj:

$iCounter counter( );

4. wtaw zmienna $iCounter gdzies do kodu np. templates/page.tpl

Mysle, ze bedziesz mial to porzadnie zrobione a ten tips pozwole sobie wstawic do dokumentacji.

Do góry
o nas | kontakt