daily pastebin goal
12%
SHARE
TWEET

Problem

a guest Dec 15th, 2017 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. session_start();
  3. $counter_name = "counter.txt";
  4. // Check if a text file exists. If not create one and initialize it to zero.
  5. if (!file_exists($counter_name)) {
  6.   $f = fopen($counter_name, "w");
  7.   fwrite($f,"0");
  8.   fclose($f);
  9. }
  10. // Read the current value of our counter file
  11. $f = fopen($counter_name,"r");
  12. $counterVal = fread($f, filesize($counter_name));
  13. fclose($f);
  14. // Has visitor been counted in this session?
  15. // If not, increase counter value by one
  16. if(!isset($_SESSION['hasVisited'])){
  17.   $_SESSION['hasVisited']="yes";
  18.   $counterVal++;
  19.   $f = fopen($counter_name, "w");
  20.   fwrite($f, $counterVal);
  21.   fclose($f);
  22. }
  23.  
  24. echo "Liczba odwiedzin: $counterVal"; ?>
RAW Paste Data
Top