Advertisement
Guest User

Problem

a guest
Dec 15th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.67 KB | None | 0 0
  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"; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement