Einzelnen Beitrag anzeigen

Benutzerbild von malo
malo

Registriert seit: 19. Sep 2004
2.115 Beiträge
 
#9

Re: Zugriffszähler für Homepage

  Alt 5. Feb 2006, 16:53
Du brauchst eine .php-Datei. Da kannst du ganz normal deinen HTML-Code reinschreiben, wie du lustig bist. An den Stellen, wo PHP vorkommt, fügst du einfach den Quelltext ein.
Code:
<? function getCounter($counterID)
{
   // each counter value is stored inside a unique file
   // We use $counterID as a part of the file name
   // Example: file name will be "counter1.txt" if $counterID is set to "1"

   $fileName = "counter".$counterID.".txt";

   if( file_exists($fileName) ) {
      list($numVisitors)=file($fileName); // Read contents from the file
   } else {
      $numVisitors=0; // This is the first time the page is accessed
   }

   $numVisitors=$numVisitors+1; // Increase the count

   $fil=fopen($fileName,"w");   // Open the file to replace old value
   fputs($fil,$numVisitors);    // Write the new count to the file
   fclose($fil);           // Close the file
   return $numVisitors;     // Return the new count
}
?>
Das ist ja eine Funktion, wie man erkennen kann. Praktischerweise ist der bereits in den PHP-Scriptbegrenzern <? und ?>.
Das kannst du erst einmal irgendwo an den Anfang kopieren.
Da, wo du angezeigt haben willst, wieviele Besucher deine Homepage hat, musst du folgendes einfügen:
Code:
<? echo getCounter("1"); ?>
Das gibt dir dann die Anzahl der Aufrufe aus
  Mit Zitat antworten Zitat