PHP-Einfach.de
  • PHP Tutorial
  • MySQL Tutorial
  • Für Fortgeschrittene
  • Webhosting
  • Forum

Besucherzähler mit Reload-Sperre

10. Februar 2020
  1. Home
  2. »
  3. Für Fortgeschrittene
  4. »
  5. Script-Beispiele
  6. »
  7. Besucherzähler mit Reload-Sperre

Möchte man feststellen, wie gut eine Seite besucht ist, benötigt man einen Counter. Aber Counter ohne IP-Sperre bringen nicht viel, weil immer wenn der Besucher auf die nächste Seite geht, wird der Counterstand erhöht. So erhält man eigentlich nur das Page Impressum. Man möchte aber die Besucherzahl eigentlich wissen.

Dieser Counter arbeitet mit Sessions, wenn der Besucher die Seite zum ersten Mal aufruft, wird eine Session für diesen gesetzt, später muss man nur noch überprüfen, ob diese Session gesetzt ist oder nicht.

Ganz oben, bevor wir irgendetwas ausgeben, egal ob mit PHP oder HTML, muss folgendes stehen:

1
2
3
4
<?php
session_set_cookie_params(10800);
session_start();
?>

Mit session_set_cookie_params(10800); stellen wir ein, wie lange der Session Cookie leben soll, hier sind es 10800 Sekunden (1 Stunde hat 3600 Sekunden, 3 Stunden = 10800 Sek.).
Mit session_start(); erlauben wir PHP, mit Session zu arbeiten.

Als nächstes kommt der Counter:

1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
$counterstand = intval(file_get_contents("counter.txt"));
 
if(!isset($_SESSION['counter_ip']))
   {
   $counterstand++;
   file_put_contents("counter.txt", $counterstand);
 
   $_SESSION['counter_ip'] = true;
   }
 
echo $counterstand;
?>

Mehr Infos zum Umgang mit Dateien erhaltet ihr in unserem Tutorial zum Thema Dateien lesen.

Autor: Nils Reimers
Zurück: PDF per PHP erstellen – PDF-Rechnung
Weiter: Kontaktformular

Für Fortgeschrittene

  • Objektorientierte Programmierung
  • PHP Sicherheit
  • Script-Beispiele
    • Loginscript
    • E-Mails mit Anhang versenden
    • Gästebuch
    • PDFs erstellen
    • Besucherzähler mit Reload-Sperre
    • Kontaktformular
    • Logfiles mit PHP generieren
    • URLs im Text identifizieren
  • Codeschnipsel
  • Stellenmarkt
Mit freundlicher Unterstützung von:
  • Punkt191 Werbeagentur
  • DGUV V3
  • DGUV 3
  • CasinoAndy Finland
  • Casinopilot24.com
  • Neueonline-Casinos.com
  • Decasinos.de
  • Privatkredit247.com
  • CasinoHEX.at
  • Online Casino Spielautomaten
  • Casinofrog.com
  • parhaatuudetkasinot.com
  • Mr Bet Casino Spiele

Hoster – Geringste Ausfallzeit

  1. webgo Ø 0 Min.
  2. Linevast Ø 2 Min.
  3. netcup Ø 2 Min.
  4. Mittwald Ø 5 Min.
  5. dogado Ø 6 Min.
  6. checkdomain Ø 8 Min.
  7. All-Inkl.com Ø 9 Min.
  8. manitu Ø 10 Min.
  9. bplaced Ø 11 Min.
  10. Host Europe Ø 15 Min.
» Mehr erfahren

Impressum | Datenschutz | Auf PHP-Einfach.de werben

© PHP-Einfach.de 2003 - 2022

Um dich beim Lernen von PHP und MySQL zu unterstützen verwenden wir Cookies. OK Weitere Infos
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Notwendige
immer aktiv

Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.

Nicht notwendige

Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.