• Jetzt anmelden. Es dauert nur 2 Minuten und ist kostenlos!

Online-Counter erstellen

blueangel

Neues Mitglied
Hallo! Bin auf Eure Hilfe angewiesen... Würde gerne einen OnlineCounter auf meine HP einbinden (möglichst einen ohne Werbung). Kenne mich nun mit html etwas aus, mit php sehr wenig, habe phpmyadmin auf dem rechner.Habe die Datei auf der Seite von Herrn Born runtergelade, und mich streng an die Anweisungen gehalten. Leider klappt es nicht, obwohl php auf meinem Rechner funktioniert. Nachdem ich anschließend noch die .htaccess hochgeladen hatte und auf dem Server ausprobiert habe, ob überhaupt php Seiten funktionieren, bin ich mittlerweile ratlos...
Habe also die Datei counter.php sowie counter.txt und counter.gif auf meinem Web-Server drauf. Die Dateien stehen nicht in nem Verzeichnis, sondern genau dort, wo auch die index.html steht. In der Index.html habe ich anschließend folgendes eingefügt:
HTML:
<?php
include ("counter.php");
?

Die PHP-Datei lautet:


PHP:
<?
/*
Counter Information
Anbieter: http://www.vonderborn.com
Autor: Philipp von der Born
Der Link im Icon, darf nicht entfernt werden.
*/
// ip-sperre in sekunden
$expire = 600;
$filename = "counter.txt";
if (file_exists($filename)) 
{
   $ignore = false;
   $current_agent = (isset($_SERVER['HTTP_USER_AGENT'])) ? addslashes(trim($_SERVER['HTTP_USER_AGENT'])) : "no agent";
   $current_time = time();
   $current_ip = $_SERVER['REMOTE_ADDR']; 
 
   // daten einlesen
   $c_file = array();
   $handle = fopen($filename, "r");
 
   if ($handle)
   {
      while (!feof($handle)) 
      {
         $line = trim(fgets($handle, 4096)); 
   if ($line != "")
      $c_file[] = $line;    
      }
      fclose ($handle);
   }
   else
      $ignore = true;
 
   // bots ignorieren   
   if (substr_count($current_agent, "bot") > 0)
      $ignore = true;
 
 
   // hat diese ip einen eintrag in den letzten expire sec gehabt, dann igornieren?
   for ($i = 1; $i < sizeof($c_file); $i++)
   {
      list($counter_ip, $counter_time) = explode("||", $c_file[$i]);
   $counter_time = trim($counter_time);
 
   if ($counter_ip == $current_ip && $current_time-$expire < $counter_time)
   {
      // besucher wurde bereits gezählt, daher hier abbruch
   $ignore = true;
   break;
   }
   }
 
   // counter hochzählen
   if ($ignore == false)
   {
      if (sizeof($c_file) == 0)
      {
      // wenn counter leer, dann füllen      
   $add_line1 = date("z") . ":1||" . date("W") . ":1||" . date("n") . ":1||" . date("Y") . ":1||1||1||" . $current_time . "\n";
   $add_line2 = $current_ip . "||" . $current_time . "\n";
 
   // daten schreiben
   $fp = fopen($filename,"w+");
   if ($fp)
         {
      flock($fp, LOCK_EX);
   fwrite($fp, $add_line1);
      fwrite($fp, $add_line2);
   flock($fp, LOCK_UN);
      fclose($fp);
   }
 
   // werte zur verfügung stellen
   $day = $week = $month = $year = $all = $record = 1;
   $record_time = $current_time;
   $online = 1;
   }
      else
   {
      // counter hochzählen
   list($day_arr, $week_arr, $month_arr, $year_arr, $all, $record, $record_time) = explode("||", $c_file[0]);
 
   // day
   $day_data = explode(":", $day_arr);
   $day = $day_data[1];
   if ($day_data[0] == date("z")) $day++; else $day = 1;
 
   // week
   $week_data = explode(":", $week_arr);
   $week = $week_data[1];
   if ($week_data[0] == date("W")) $week++; else $week = 1;
 
   // month
   $month_data = explode(":", $month_arr);
   $month = $month_data[1];
   if ($month_data[0] == date("n")) $month++; else $month = 1;
 
   // year
   $year_data = explode(":", $year_arr);
   $year = $year_data[1];
   if ($year_data[0] == date("Y")) $year++; else $year = 1;
 
   // all
   $all++;
 
   // neuer record?
   $record_time = trim($record_time);
   if ($day > $record)
   {
      $record = $day;
   $record_time = $current_time;
   }
 
   // speichern und aufräumen und anzahl der online leute bestimmten
 
   $online = 1;
 
   // daten schreiben
   $fp = fopen($filename,"w+");
   if ($fp)
         {
      flock($fp, LOCK_EX);
   $add_line1 = date("z") . ":" . $day . "||" . date("W") . ":" . $week . "||" . date("n") . ":" . $month . "||" . date("Y") . ":" . $year . "||" . $all . "||" . $record . "||" . $record_time . "\n";   
      fwrite($fp, $add_line1);
 
      for ($i = 1; $i < sizeof($c_file); $i++)
            {
               list($counter_ip, $counter_time) = explode("||", $c_file[$i]);
 
            // übernehmen
         if ($current_time-$expire < $counter_time)
            {
               $counter_time = trim($counter_time);
      $add_line = $counter_ip . "||" . $counter_time . "\n";
         fwrite($fp, $add_line);
         $online++;
            }
            }
      $add_line = $current_ip . "||" . $current_time . "\n";
      fwrite($fp, $add_line);
      flock($fp, LOCK_UN);
      fclose($fp);
      }
   }
   }
   else
   {
      // nur zum anzeigen lesen
   if (sizeof($c_file) > 0)
      list($day_arr, $week_arr, $month_arr, $year_arr, $all, $record, $record_time) = explode("||", $c_file[0]);
   else
   list($day_arr, $week_arr, $month_arr, $year_arr, $all, $record, $record_time) = explode("||", date("z") . ":1||" . date("W") . ":1||" . date("n") . ":1||" . date("Y") . ":1||1||1||" . $current_time);
 
   // day
   $day_data = explode(":", $day_arr);
      $day = $day_data[1];
 
   // week
   $week_data = explode(":", $week_arr);
   $week = $week_data[1];
 
   // month
   $month_data = explode(":", $month_arr);
   $month = $month_data[1];
 
   // year
   $year_data = explode(":", $year_arr);
   $year = $year_data[1];
 
   $record_time = trim($record_time);
 
   $online = sizeof($c_file) - 1;
   }
?>
<table cellpadding="1" cellspacing="0" style="border:1px solid #000000">
  <tr> 
    <td width="150"><b><font face="Arial, Helvetica, sans-serif" size="2"><a href="http://www.nautic-shop.de/" target="_blank"><img src="counter.gif" width="16" height="16" border="0" /></a> Besucher Statistik </font></b>    </td>
  </tr>
  <tr> 
    <td style="border-top:1px solid #000000"> 
      <font face="Arial, Helvetica, sans-serif" size="1">
      &raquo; <? echo $online; ?> Online<br>
      &raquo; <? echo $day; ?> Heute<br>
   &raquo; <? echo $week; ?> Woche<br>
   &raquo; <? echo $month; ?> Monat<br>
   &raquo; <? echo $year; ?> Jahr<br>
      &raquo; <? echo $all; ?> Gesamt
        <hr noshade="noshade" />
  Rekord: <? echo $record; ?> (<? echo date("d.m.Y", $record_time) ?>)</font>
  <div align="center">
      <font style="font-size:9px;" face="Arial, Helvetica, sans-serif">(<a href="http://www.vonderborn.com/php_counter_script.php" target="_blank">PHP Counter</a>)</font></div>
    </td>
  </tr>
</table>
<?
}
?>

Ich weiss, ist ganz schön peinlich... aber ich komm einfach nicht weiter und weiss langsam nicht mehr ein noch aus...
Herzlichen Dank für Eure Hilfe!
 
*.html bzw. deine index.html wird sicherlich nicht von PHP geparsed. Entweder du benennst sie in index.php um, oder stellst ein, dass html-Dateien mit PHP geparsed werden:
Code:
AddType application/x-httpd-php .html

P.S. das Script dort braucht keine Datenbank.
 
In meiner .htaccess steht dann folgendes drin:

Code:
AddType x-mapp-php5 .php
AddHandler x-mapp-php5 .php
AddType application/x-httpd-php .html

Wenn die Datei so aussieht, kommt beim Aufruf der Index-Datei immer die Frage ob ich die Datei downloaden will... Die eigentliche Indexseite öffnet sich dann überhaupt nimmer...???
 
Code:
AddType x-mapp-php5 .php
AddHandler x-mapp-php5 .php
AddType x-mapp-php5 .html
Der Content-Type ist bei deinem Hoster anders konfiguriert (wohl damit man wahlweise PHP4 und PHP5 benutzen kann).
 
VIELEN VIELEN DANK!!!!!
Es funktioniert!!!!
Nochmals Danke!!!!!!!!

Kleine Frage noch für mich zum besseren Verständnis...
Was bedeuten die einzelnen Befehle in der .htaccess datei genau und was ist die .htaccess Datei?
 
Zurück
Oben